none
verknüpfte Felder Datenübernahme im Formular RRS feed

  • Frage

  • Hi, ich habe ein neues Rechnungseingabeformular erstellt. Diese Entiät habe ich verknüpft mit der Entität Produkte. In der Entität Produkte habe ich das Felde Listenpreis mit einem Wert gefüllt. Jetzt habe ich mir in meinem Rechnungsformular auch ein Feld Einzelpreis erstellt. Die beiden Felder Listenpreis der Entität Produkte und das Feld Einzelpreis meines Rechnungsformulars habe ich auch verknüpft. Jetzt dachte ich, wenn ich in meinem Rechnungsformular eine Produkt auswähle wird mein Feld Einzelpreis automatisch auf Grund der Verknüpfung gefüllt. Es geschieht aber nichts. Wie bekomme ich den Zugriff auf den Einzelpreis(Listenpreis) des Produktes?
    Ich hoffe, es ist nicht zu kompliziert beschrieben.

    Gruß

    Sven
    Montag, 20. Juli 2009 10:19

Antworten

  • Hi Sven,

    ja, das wollte ich, aber anscheinend habe ich nicht mehr den kompletten Link, deshalb hier der Code, der hinter dem Link steckt:
    • var rId = crmForm.all.regardingobjectid;
    
    if(rId != null && rId.DataValue != null && rId.DataValue[0] != null)
    {
      if(rId.DataValue[0].typename == "lead" && rId.DataValue[0].name == "")
      {
        var leadCompanyname = GetAttributeValueFromID("lead", rId.DataValue[0].id, "companyname");
    
        var lookupData = new Array();
        var lookupItem= new Object();
        lookupItem.id = rId.DataValue[0].id;
        lookupItem.typename = rId.DataValue[0].typename;
        lookupItem.name = leadCompanyname;
    
        lookupData[0] = lookupItem;
        rId.DataValue = lookupData;
      }
    }
    
    
    function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName)
    {
        var sXml = "";
        var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    
        // set up the SOAP message
        sXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
        sXml += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"";
        sXml += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
        sXml += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
        sXml += GenerateAuthenticationHeader()
        sXml += " <soap:Body>";
        sXml += " <entityName xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sEntityName + "</entityName>";
        sXml += " <id xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sGUID + "</id>";
        sXml += " <columnSet xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\"";
        sXml += " xmlns:q=\"http://schemas.microsoft.com/crm/2006/Query\"";
        sXml += " xsi:type=\"q:ColumnSet\"><q:Attributes><q:Attribute>" + sAttributeName + "</q:Attribute></q:Attributes></columnSet>";
        sXml += " </soap:Body>";
        sXml += " </soap:Envelope>";
    
        // send the message to the CRM Web service
        oXmlHttp.Open("POST", "/MsCrmServices/2006/CrmService.asmx", false);
        oXmlHttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
        oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        oXmlHttp.setRequestHeader("Content-Length", sXml.length);
        oXmlHttp.send(sXml);
    
        // retrieve response and find attribute value
        var result = oXmlHttp.responseXML.selectSingleNode("//q1:" + sAttributeName);
        if (result == null)
            return "";
        else
            return result.text;
    }
    

     
    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Montag, 20. Juli 2009 14:41

Alle Antworten

  • Hallo Sven,

    da hast du einen kleinen Denkfehler eingebaut. Der Einzelpreis würde nur übernommen, wenn du innerhalb deines Rechnungseingabeformulares ein neues Produkt anlegen würdest., und das auch nur, wenn es aus sicht deines Eingabeformulares um eine 1:n Verknüpfung handelt.

    Wenn du in deinem Formular eine n:1 Verknüpfung zwischen Rechnung und Produkt verwendest, kannst du den Wert über JavaScript ermitteln, siehe

    http://mscrm4ever.blogspot.com/2009/03/displaying-lookup-with-related-entity.html
    http://www.stunnware.com/crm2/data/JS34.htm


    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Montag, 20. Juli 2009 10:38
  • Hallo Michael,

    ich habe mir die Codes angeschaut, aber ich frage mich wie ich Zugriff auf das Feld Listenpreis in der Produktentität bekomme. Das ist ja als Attribut in meinem Rechnungformular nicht vorhanden, also kann ich doch nicht mit crmform.all.<Feldname> drauf zugreifen, oder doch?

    Gruß

    Sven
    Montag, 20. Juli 2009 13:47

  • Hallo Sven,

    nein, mit crmFom.all.... kommst du nicht an das von dir gewünschte Feld. Du musst schon per JavaScript eine SOAP-Message an den Server richten und dann die Antwort entsprechend auswerten.
    Siehe z.B. hier:
     

    http://social.microsoft.com/Forums/en-US/crm/threads


    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Montag, 20. Juli 2009 14:09
  • Sorry, ich stehe gerade auf dem Schlauch. Wolltest du auf einen bestimmten Thread verweisen?

    Gruß

    Sven
    Montag, 20. Juli 2009 14:32
  • Hi Sven,

    ja, das wollte ich, aber anscheinend habe ich nicht mehr den kompletten Link, deshalb hier der Code, der hinter dem Link steckt:
    • var rId = crmForm.all.regardingobjectid;
    
    if(rId != null && rId.DataValue != null && rId.DataValue[0] != null)
    {
      if(rId.DataValue[0].typename == "lead" && rId.DataValue[0].name == "")
      {
        var leadCompanyname = GetAttributeValueFromID("lead", rId.DataValue[0].id, "companyname");
    
        var lookupData = new Array();
        var lookupItem= new Object();
        lookupItem.id = rId.DataValue[0].id;
        lookupItem.typename = rId.DataValue[0].typename;
        lookupItem.name = leadCompanyname;
    
        lookupData[0] = lookupItem;
        rId.DataValue = lookupData;
      }
    }
    
    
    function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName)
    {
        var sXml = "";
        var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    
        // set up the SOAP message
        sXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
        sXml += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"";
        sXml += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
        sXml += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
        sXml += GenerateAuthenticationHeader()
        sXml += " <soap:Body>";
        sXml += " <entityName xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sEntityName + "</entityName>";
        sXml += " <id xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sGUID + "</id>";
        sXml += " <columnSet xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\"";
        sXml += " xmlns:q=\"http://schemas.microsoft.com/crm/2006/Query\"";
        sXml += " xsi:type=\"q:ColumnSet\"><q:Attributes><q:Attribute>" + sAttributeName + "</q:Attribute></q:Attributes></columnSet>";
        sXml += " </soap:Body>";
        sXml += " </soap:Envelope>";
    
        // send the message to the CRM Web service
        oXmlHttp.Open("POST", "/MsCrmServices/2006/CrmService.asmx", false);
        oXmlHttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
        oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        oXmlHttp.setRequestHeader("Content-Length", sXml.length);
        oXmlHttp.send(sXml);
    
        // retrieve response and find attribute value
        var result = oXmlHttp.responseXML.selectSingleNode("//q1:" + sAttributeName);
        if (result == null)
            return "";
        else
            return result.text;
    }
    

     
    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Montag, 20. Juli 2009 14:41