none
Formularübergreifendes Skripten - Problem RRS feed

  • Frage

  • Moin,

    habe Probleme bei folgenden Code:

    var authenticationHeader = GenerateAuthenticationHeader();
    
    
    
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    
    xmlhttp.Open('GET', 'http://crmserver/mscrmservices/2006/crmservice.asmx', false);
    
    xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    
    xmlhttp.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple');
    
    
    
    var xmlPost = "<?xml version='1.0' encoding='utf-8'?>"+"\n\n"+"<soap:Envelope"+ 
    
     ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+
    
     ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
    
     ' xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
    
      authenticationHeader +
    
     ' <soap:Body>' + 
    
     ' <query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query" xsi:type="q1:QueryByAttribute" xmlns="http://schemas.microsoft.com/crm/2006/WebServices">'+
    
     ' <q1:EntityName>product</q1:EntityName>'+ 
    
     ' <q1:ColumnSet xsi:type="q1:AllColumns" />'+ 
    
     ' <q1:Attributes>'+ 
    
     ' <q1:Attribute>productnumber</q1:Attribute>'+ 
    
     ' </q1:Attributes>'+ 
    
     ' <q1:Values>'+ 
    
     ' <q1:Value xsi:type="xsd:string">*produktnummer*</q1:Value>'+ 
    
     ' </q1:Values>'+ 
    
     ' </query>'+ 
    
     ' </soap:Body>'+ 
    
     ' </soap:Envelope>'; 
    
    
    
    xmlhttp.send(xmlPost);
    
    
    
    var xmlResponse = xmlhttp.responseXML;
    
    
    
    var price= xmlResponse.selectNodes("//BusinessEntities/price");
    
    
    
    

    Und der Code bekommt folgende Antwort (xmlResponse):

    <?xml version="1.0"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RetrieveMultipleResult EntityName="product" MoreRecords="0" PagingCookie="" xmlns="http://schemas.microsoft.com/crm/2006/WebServices"><BusinessEntities/></RetrieveMultipleResult></soap:Body></soap:Envelope>

    Mein Problem hierbei ist, dass die response nicht die gewünschten Daten enthällt. Demnach geht natürlich auch die Variable "price" nicht.

    Für *produktnummer* habe ich natürlich eine vorhandene Produktnummer genommen, um wenigstens etwas rauszubekommen.

    Ich bitte euch (wiedermal) um baldige Hilfe, da ich nicht weiterkomme!

    mfg Jasper

    Donnerstag, 10. Juni 2010 13:51

Antworten

  • Hallo Jasper,

    irgend wie fehlt mir in deinem Code die Query. Versuch mal diesen Code, der funktioniert.

    Es ist auch immer eine gute Idee, nicht alle Felder der Entität zu holen, sondern nur die, die du auch wirklich benötigst.

    var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +

    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +

    GenerateAuthenticationHeader()+

    "  <soap:Body>" +

    "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +

    "        <q1:EntityName>product</q1:EntityName>" +

    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +

    "          <q1:Attributes>" +

    "            <q1:Attribute>product_feld1</q1:Attribute>" +

    "            <q1:Attribute>product_feld2</q1:Attribute>" +

    "          </q1:Attributes>" +

    "        </q1:ColumnSet>" +

    "        <q1:Distinct>false</q1:Distinct>" +

    "        <q1:Criteria>" +

    "          <q1:FilterOperator>And</q1:FilterOperator>" +

    "          <q1:Conditions>" +

    "            <q1:Condition>" +

    "              <q1:AttributeName>productnumber</q1:AttributeName>" +

    "              <q1:Operator>Equal</q1:Operator>" +

    "              <q1:Values>" +

    "                <q1:Value xsi:type=\"xsd:string\">produktnummer</q1:Value>" +

    "              </q1:Values>" +

    "            </q1:Condition>" +

    "          </q1:Conditions>" +

    "        </q1:Criteria>" +

    "      </query>" +

    "    </RetrieveMultiple>" +

    "  </soap:Body>" +

    "</soap:Envelope>";

     


    Viele Grüße

    Michael Sulz
    MVP für Microsoft Dynamics CRM
    • Als Antwort vorgeschlagen Michael Sulz Freitag, 11. Juni 2010 07:11
    • Als Antwort markiert Jasper Gandyra Freitag, 11. Juni 2010 11:28
    Freitag, 11. Juni 2010 07:11

Alle Antworten

  • Hallo Jasper,

    irgend wie fehlt mir in deinem Code die Query. Versuch mal diesen Code, der funktioniert.

    Es ist auch immer eine gute Idee, nicht alle Felder der Entität zu holen, sondern nur die, die du auch wirklich benötigst.

    var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +

    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +

    GenerateAuthenticationHeader()+

    "  <soap:Body>" +

    "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +

    "        <q1:EntityName>product</q1:EntityName>" +

    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +

    "          <q1:Attributes>" +

    "            <q1:Attribute>product_feld1</q1:Attribute>" +

    "            <q1:Attribute>product_feld2</q1:Attribute>" +

    "          </q1:Attributes>" +

    "        </q1:ColumnSet>" +

    "        <q1:Distinct>false</q1:Distinct>" +

    "        <q1:Criteria>" +

    "          <q1:FilterOperator>And</q1:FilterOperator>" +

    "          <q1:Conditions>" +

    "            <q1:Condition>" +

    "              <q1:AttributeName>productnumber</q1:AttributeName>" +

    "              <q1:Operator>Equal</q1:Operator>" +

    "              <q1:Values>" +

    "                <q1:Value xsi:type=\"xsd:string\">produktnummer</q1:Value>" +

    "              </q1:Values>" +

    "            </q1:Condition>" +

    "          </q1:Conditions>" +

    "        </q1:Criteria>" +

    "      </query>" +

    "    </RetrieveMultiple>" +

    "  </soap:Body>" +

    "</soap:Envelope>";

     


    Viele Grüße

    Michael Sulz
    MVP für Microsoft Dynamics CRM
    • Als Antwort vorgeschlagen Michael Sulz Freitag, 11. Juni 2010 07:11
    • Als Antwort markiert Jasper Gandyra Freitag, 11. Juni 2010 11:28
    Freitag, 11. Juni 2010 07:11
  • Mahlzeit,

    Funktioniert nun. Ich danke dir malwieder!

    mfg Jasper

    Freitag, 11. Juni 2010 11:28