none
'Object expected' error when trying to use CRM 4 code in CRM 3.0 JScript

    Question

  • I too had the 'Object expected' error when trying to use CRM 4 code in CRM 3.0 JScript. I am auto-populating a field in the Case form.  When the Customer is selected, the onChange event fires JScript to retrieve the value of a custom field.

    Right now I'm stuck with a call to the following which returns the 'Object expected' error.
          resultXml.selectSingleNode("//q1:new_supportlevel").nodeTypedValue;

    Our custom field 'new_supportlevel' is a picklist in the Account entity so I changed the code to use different syntax as follows and now it errors out saying "Error: 'selectSingleNode(...)' is null or not an object" .
          resultXml.selectSingleNode("//q1:new_supportlevel").getAttribute("name");

    Is there a CRM 3 equivalent to selectSingleNode or am I missing something?

    -Ryan

     

    Wednesday, November 03, 2010 1:12 AM

Answers

  • rbrad,

    No, there are two missing node structures in your QueryByAttribute call.  Also, for a QueryByAttribute call, "entityName" isn't formatted properly.  I'll include them in the modified version of your latest code:

      " <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryByAttribute' xmlns='http://schemas.microsoft.com/crm/2006/WebServices'>" +
       " <q1:EntityName>account</q1:EntityName>" +
       " <q1:ColumnSet xsi:type='q1:ColumnSet'>" +
        " <q1:Attributes>" +
         " <q1:Attribute>name</q1:Attribute>" +
        " </q1:Attributes>" +
       " </q1:ColumnSet>" +
       " <q1:Attributes>" +
       " <q1:Attribute>accoundid</q1:Attribute>" +
       " </q1:Attributes>" +
       " <q1:Values>" +
       " <q1:Value xsi:type='xsd:string'>" + accountId + "</q1:Value>" +
       " </q1:Values>" +
      " </query>" +
    
    Since you've changed from a "Retrieve" call to a "RetrieveMultiple" call (by using "QueryByAttribute"), you need to also use this line:
     xmlhttp.setRequestHeader("SOAPAction"
    , "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple"
    );
    

     


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 3:19 PM

All replies

  • The function "selectSingleNode" is an XML DOM method , and it's made available by browsers through Javascript.  It does not come from CRM 3.  Your error comes from the fact that you're calling an attribute (.nodeTypedValue) or a method (.getAttribute("name")) on a null pointer... which means that resultXml.selectSingleNode("//q1:new_supportlevel") returned null.  This means that no node by the name "new_supportlevel" was found in the results, and could be because there is no value for that attribute on the record (since neither CRM 3, nor CRM 4 return attributes with no values).

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, November 03, 2010 2:21 AM
  • Thanks for the sanity check, David! 

    That makes perfect sense.  I'm a noob to javascript.  Is there a good debugger I can use to walk through this code?  I'm a bit of a control freak and not being able to see the gears turn in my code is making my head spin.  I'm using VS 2005 but client side script objects (i.e. crmForm) are undefined.

    Also, the sample I'm using is from this script written for CRM 4.0 .  Is it possible that the web service end point (and the XML) is different in CRM 3.0?

    For reference here is the code I'm using in the Case form Customer field's onChange event.  'new_supportlevel' is a custom PickList field we've added to the Account entity.  The objective is to autopopulate the "Support Level" field on the Case form when the Customer is selected.

    var accountLookup = new Array(); 
    accountLookup = crmForm.all.customerid.DataValue;
    
    if(accountLookup != null) 
    { 
      var accountId = accountLookup[0].id.replace(/^{+|}+$/g, ""); 
    
      var serverUrl = "/mscrmservices/2007/crmservice.asmx"; 
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
      xmlhttp.open("POST",serverUrl,false); 
      xmlhttp.setRequestHeader("Content-Type","text/xml; charset=utf-8"); 
      xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); 
    
      var message =  
      [ 
        "<?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'>", 
        "<soap:Body>", 
        "  <Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", 
        "    <entityName>account</entityName>", 
        "    <id>", accountId, "</id>", 
        "    <columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>", 
        "      <q1:Attributes>", 
        "        <q1:Attribute>new_supportlevel</q1:Attribute>", 
        "      </q1:Attributes>", 
        "    </columnSet>", 
        "  </Retrieve>", 
        "</soap:Body>", 
        "</soap:Envelope>" 
      ].join(""); 
    
      xmlhttp.send(message); 
      //Capture the result. 
      var resultXml = xmlhttp.responseXML; 
     
      //Check for errors. 
      var errorCount = resultXml.selectNodes('//error').length; 
      if (errorCount != 0) 
      { 
         var msg = resultXml.selectSingleNode('//description').nodeTypedValue; 
         alert(msg); 
      } else { 
    
         alert("'Object required' error here...");
         var strSupportLevel = resultXml.selectSingleNode("//q1:new_supportlevel").nodeTypedValue;
    
         alert("'Error: selectSingleNode(...) is null or not an object' error here...");
         var strSupportLevel = resultXml.selectSingleNode("//q1:new_supportlevel").getAttribute("name");
    
    //     crmForm.all.new_supportlevel.DataValue = strSupportLevel;
      } 
    }
    
    Any help is greatly appreciated!

    -Ryan

     

    Wednesday, November 03, 2010 1:18 PM
  • It's not only possible that the web-service end points are different, it's certain.  For the most part, you just need to switch out "2007" for "2006", as far as I understand The CRM 3 SDK is the best reference point.  As for debugging and walking through code, IE8 has built-in Developer Tools that can be helpful (hit F12 on a page to access them).  I've found, however, that to start the debugging, you can use the line:

    debugger;
    

    The other thing I'm going to suggest is that you refrain from using the "replace()" function on the Account's ID.  This is all you should need:

    var accountId = accountLookup[0].id;
    

    However, you should always check that the return of a function is exactly what you think it should be and not something else, before you go using it in ways that break your assumption:

       if (resultXml.selectSingleNode("//q1:new_supportlevel") != null) {
        var strSupportLevel = resultXml.selectSingleNode("//q1:new_supportlevel").nodeTypedValue;
        var strSupportLevel = resultXml.selectSingleNode("//q1:new_supportlevel").getAttribute("name");
       } else {
        alert("The attribute 'new_supportlevel' has no value, or was not returned.");
       }
    
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, November 03, 2010 3:40 PM
  • Progress!  After changing the end point to use "2006" it is returning a server error.  The error returned is "Invalid argument".

    So at least I know that the server is actually processing the request and I'm getting more than a null return.

    I tried changing the following line to use [accountid] instead of my custom picklist attribute [new_supportlevel] and the same error was returned.
        " <q1:Attribute>new_supportlevel</q1:Attribute>"
    ,
    now reads
        " <q1:Attribute>accountid</q1:Attribute>" ,

    Is there a difference between CRM 3 v 4 in how Entities, Column Sets, or Attributes are referenced?

     

     

    Wednesday, November 03, 2010 6:46 PM
  • Are you still using the "replace()" function to strip characters from the accountId value?  If not, perhaps I was mistaken and you should put it back in.  As near as I can tell, the implementation of the Retrieve method is identical in CRM 3 to CRM 4, and there there is no variation of the declaration of Entities, ColumSet, or Attributes.  However, for testing purposes, perhaps it would be wise to use the following columnSet declaration:

    <columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:AllColumns'>
    

    I've never written CRM 3 JS code to work with the Web Services, but I can't find anything that would lead me to believe that there is a difference between CRM 3 and CRM 4 (with the Retrieve method), aside from the service-endpoint.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, November 03, 2010 7:47 PM
  • Hi

    With CRM3 the returned xml is different to the returned xml from crm4 because of the namespace. CRM3 does'nt use namespace with the returned xml so you should not qualify your attributes with q1: i.e. you should directly reference the element name as follows

    resultXml.selectSingleNode("//new_supportlevel"
    ).getAttribute("name"
    );

    Also you can inspect the returned xml as follows

    alert(
    xmlhttp.responseXML); this should give you some idea

    Here is a sample code from CRM3

    var serverUrl = "http://xyzServer/mscrmservices/2006";
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    xmlhttp.open("POST", serverUrl + "/crmservice.asmx", false);
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
    xmlhttp.send("<?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">'+
    ' <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>new_inspectionteammember</q1:EntityName>'+
    ' <q1:ColumnSet xsi:type="q1:ColumnSet">'+
    ' <q1:Attributes>'+
    ' <q1:Attribute>new_paymentdays</q1:Attribute>'+
    ' <q1:Attribute>new_teammemberid</q1:Attribute>'+
    ' <q1:Attribute>new_contractid</q1:Attribute>'+
    ' </q1:Attributes>'+
    ' </q1:ColumnSet>'+
    ' <q1:Attributes>'+
    ' <q1:Attribute>new_teammemberid</q1:Attribute>'+
    ' </q1:Attributes>'+
    ' <q1:Values>'+
    ' <q1:Value xsi:type="xsd:string">{EAF42DF0-CC20-DC11-8F88-00163504B54F}</q1:Value>'+
    ' </q1:Values>'+
    ' </query>'+
    ' </soap:Body>'+
    ' </soap:Envelope>');

    //Capture the result. var resultXml = xmlhttp.responseXML; //Check for errors. var errorCount = resultXml.selectNodes('//error' ).length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description' ).nodeTypedValue; alert(msg); }
      else
    { alert("'Object required' error here..." ); var strSupportLevel = resultXml.selectSingleNode("//new_contractid" ).nodeTypedValue; alert("'Error: selectSingleNode(...) is null or not an object' error here..." ); var strSupportLevel = resultXml.selectSingleNode("//new_contractid" ).getAttribute("name" ); 
       } }



    Hope this helps. Amar

    CRM Forum Guidance on how to Help Us Help You

    • Proposed as answer by Amarsen Reddy Wednesday, November 03, 2010 9:32 PM
    Wednesday, November 03, 2010 9:24 PM
  • Dave,
    I've tried it with and without the replace() function and both give the same result.  I've also tried the suggestion for the new columnSet decl and it also returns the invalid argument error.

    Reddy,
    Right now, the only XML I'm getting back is the error.  So Iknow that the server is processing the request.  It just doesn't like something it sees.  I'm going to pour through your sample and see if I find any discrepancies with my stuff.

    Thank you both for all the help!!

    -Ryan

     

    Wednesday, November 03, 2010 10:11 PM
  • A bit more progress ...

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

    in the line above I was missing "q1:" which produced the "invalid argument" error (now fixed).  Now I'm getting "An unexpected error occurred" in the return XML. The server processes the XML I send it and returns the error in XML.

    I suspect some minute syntax problem that I cant see.  In any other language I'd suspect incompatible data types but I'm not sure that should be an issue in javascript ...

    I've tried a lot of shake tree changes.  Some include swapping <Retrieve> with the <query> tag below and shortening the <q1:ColumnSet> tag params.  I've also removed the array with the join() call and gone with a more readable string.  So far nothing has fixed the "unexpected error".

    Here's my updated code to pull the Account Name. 

     

    var accountLookup = new Array();
    accountLookup = crmForm.all.customerid.DataValue;
    
    if(accountLookup != null) {
      //var accountId = accountLookup[0].id.replace(/^{+|}+$/g, "");
      var accountId = accountLookup[0].id;
    
      var serverUrl = "/mscrmservices/2006/crmservice.asmx";
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    
      xmlhttp.open("POST",serverUrl,false);
      xmlhttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
      xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
    
      alert("Form XML message ...");
    
      var message = "<?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'>" +
        " <soap:Body>" +
          " <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryByAttribute' xmlns='http://schemas.microsoft.com/crm/2006/WebServices'>" +
                " <entityName>account</entityName>" +
                " <id>" + accountId + "</id>" +
                " <q1:ColumnSet xsi:type='q1:ColumnSet'>" +
                  " <q1:Attributes>" +
                        " <q1:Attribute>name</q1:Attribute>" +
                  " </q1:Attributes>" +
                " </columnSet>" +
          " </query>" +
        " </soap:Body>" +
        " </soap:Envelope>";
    
      alert("This XML will be sent: \n\n" + message);
    
      xmlhttp.send(message); 
    
      alert("Capture the result ...");
    
      //Capture the result. 
      var resultXml = xmlhttp.responseXML;
      //alert("Complete resultXml.xml: \n\n" + resultXml.xml);
    
      alert("Check for errors ...");
    
      //Check for errors.
      var errorCount= resultXml.selectNodes('//error').length;
    
      //alert("Test error value...");
      if (errorCount != 0) {
        var msg = "Fault string:\n" + resultXml.selectSingleNode('//faultstring').nodeTypedValue;
        msg = msg + "\n\n" + "Description:\n" + resultXml.selectSingleNode('//description').nodeTypedValue;
        alert("THE SERVER RETURNED AN ERROR \n\n" + msg);
      } else {
        if (resultXml.selectSingleNode("//name") != null) {
    
          alert("Passed all validations GET VALUE! ...");
    
          var strSupportLevel = resultXml.selectSingleNode("//name").nodeTypedValue;
    
          alert("The returned value is: " + strSupportLevel);
    
          //crmForm.all.new_supportlevel.DataValue = strSupportLevel;
    
        } else {
          alert("The attribute 'new_supportlevel' has no value, or was not returned.");
        }
    
      }
    }

     

    Thursday, November 04, 2010 12:42 AM
  • So, QueryByAttribute requires you to set values for the Attributes and Values members.  But the other part of the problem, is in the XML itself:


          " <q1:ColumnSet xsi:type='q1:ColumnSet'>"
     +
    " <q1:Attributes>" +
    " <q1:Attribute>name</q1:Attribute>" +
    " </q1:Attributes>" +
    " </columnSet>" +

    See the bolded part?


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 3:21 AM
  • Got it!  Thanks for that!  Now I'm back to the 'Invalid argument' error.  Crafting the XML by hand is proving to be a huge problem.  There has to be a better way.

    What do you mean by "QueryByAttribute requires you to set values for the Attributes and Values members"?  Were you referring to the missing 'q1' in the </columnSet> tag?

    Thanks again for all your help.

    -Ryan

     

     

    Thursday, November 04, 2010 2:42 PM
  • You can download FetchXML tool to generate you javascript

    http://jamesewelch.wordpress.com/2009/01/28/fetchxml-builder-for-microsoft-crm/

    OR

    FetchXml Wizard from Stunnware

    http://www.stunnware.com/crm2/topic.aspx?id=Framework13


    Hope this helps. Amar

    CRM Forum Guidance on how to Help Us Help You

    Thursday, November 04, 2010 3:03 PM
  • rbrad,

    No, there are two missing node structures in your QueryByAttribute call.  Also, for a QueryByAttribute call, "entityName" isn't formatted properly.  I'll include them in the modified version of your latest code:

      " <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryByAttribute' xmlns='http://schemas.microsoft.com/crm/2006/WebServices'>" +
       " <q1:EntityName>account</q1:EntityName>" +
       " <q1:ColumnSet xsi:type='q1:ColumnSet'>" +
        " <q1:Attributes>" +
         " <q1:Attribute>name</q1:Attribute>" +
        " </q1:Attributes>" +
       " </q1:ColumnSet>" +
       " <q1:Attributes>" +
       " <q1:Attribute>accoundid</q1:Attribute>" +
       " </q1:Attributes>" +
       " <q1:Values>" +
       " <q1:Value xsi:type='xsd:string'>" + accountId + "</q1:Value>" +
       " </q1:Values>" +
      " </query>" +
    
    Since you've changed from a "Retrieve" call to a "RetrieveMultiple" call (by using "QueryByAttribute"), you need to also use this line:
     xmlhttp.setRequestHeader("SOAPAction"
    , "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple"
    );
    

     


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 3:19 PM
  • I don't really know what was wrong with the original Retrieve implementation you were using, but it seems that you're just switching gears to figure out how to get this vehicle rolling.  Retrieve and RetrieveMultiple are different in execution, but you can use them both to get the data you're looking for.  Amarsen's recommendation to use the FetchXML builder is sound, since it's well used and probably easier than formulating SOAP calls by hand.

    I don't know that it really matters much, but another bit of code I don't see you using, before the "send()" call, is:

    xmlhttp.setRequestHeader("Content-Length"
    , message.length
    );

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 3:24 PM
  • That is correct.  I was trying everything I could to get it going so I'm not surprised there are incompatible and missing nodes.  I'm building a VB.NET project now as a sanity check.

    I'm checking out those utilities right now...

     

    Thursday, November 04, 2010 3:54 PM
  • I've been able to perfrom the query I need from my VB.NET project and from FetchXML.  So I'm sure that the server is handling the Web Services calls and returning data that I need.

    Now I just need to generate useful XML.

    The XML generated in FetchXML is in a format that doesn't look like similar to what I've been using with the <query> or <Retrieve> above.  Is there a tool I can use to just cut and paste into the onChange event in CRM?

     

    Thursday, November 04, 2010 6:47 PM
  • Amarsen linked to that tool above.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 8:01 PM
  • The Stunnware tool doesn't connect to my server.  Perhaps because it is for CRM 4.0.  Should I expect FetchXML to generate the XML for the soap message?

     

    Thursday, November 04, 2010 9:26 PM
  • The FetchXML builder comes in two flavors:  CRM 3.0 and 4.0.  As for the Stunnware tool, I don't know.  I've never used either, actually.  Most of my SOAP experience is in CRM 4.0.  I'm sure the FetchXML builder will not generate the SOAP message.  If 3 is anything like 4 (and it probably is), the FetchXML has to be encoded for transmission inside a "fetchXml" node .  For that, I always use the XML Escape Tool .

    Wish I could be of more help, but I think I'm sufficiently outside of my expertise with CRM 3 at this point.  This would be a very different story with CRM 4.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, November 04, 2010 10:25 PM
  • David, you and Amarsen have already been a lot of help!

    I'm just getting my feet wet.  But so far, I can get to the data using a web services app I wrote in VB.NET, an aspx app hitting the FilteredViews, and even the FetchXML is able to return the data we need.  I just cant get a good script into the onChange event in CRM where I need it.

    It's only a matter of time at this point.

     

    Thursday, November 04, 2010 11:11 PM
  • I put out a call to more experts to solicit additional help for you.  Hopefully that call will be answered soon.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, November 05, 2010 6:16 PM
  • I think, this line is the problem:

    var serverUrl = "/mscrmservices/2007/crmservice.asmx";

    That use the CRM4 webservice, not the one for crm3. You should change 2007 to 2006.

    Here you can find a example for a working call of the webservice with crm3:

    http://blogs.msdn.com/crm/archive/2007/01/18/customizing-crm-made-easy.aspx

     


    Viele Grüße

    Michael Sulz
    MVP für Microsoft Dynamics CRM
    www.msdynamics.de
    Saturday, November 06, 2010 9:55 AM
  • Michael,

    I appreciate your input on the matter, and thank you for stopping by if you did so in response to my message to the mailing list.  However, the change you have recommended has already been tried--as it was the first recommendation I made when rbrad placed his code into the thread.  The problem isn't with accessing the service, but with various errors returned by the different methods that have been called upon it.  He was able to successfully call the service, from a VB.Net application, using (what I assume are) identical parameters.

    Rbrad,

    With a successful VB.Net interaction, you may be able to inspect the service calls and responses with a packet interceptor, or (more easily) by debugging the VB.Net application while it's doing the interaction.  That might be the easiest way to replicate a working interaction in JS.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, November 08, 2010 1:29 AM
  • Found the problem.  I had a syntax error in the SOAP request.  The format I wound up using was already suggested here but it was missing the following in the <q1:Value> tag...  I marked your post above as the answer.  Please update the following line ...  And thanks again so much!!  Many of your posts have helped.

    "         <q1:Value xsi:type='string'>" + strAccountID + "</q1:Value>" +
    Should be...
    "         <q1:Value xsi:type='xsd:string'>" + strAccountID + "</q1:Value>" +

    Here is the completed code...

    //Prepare variables for a contact to retrieve.
    var lookupItem = new Array;
    
    // Get the lookup for the primarycontactid attribute on the account form.
    lookupItem = crmForm.all.customerid.DataValue;
    
    //DEBUG: alert(lookupItem[0].name);
    //DEBUG: alert(lookupItem[0].id);
    
    var strAccountID= lookupItem[0].id;
    
    //DEBUG: alert("Form SOAP request");
    
    //Prepare the SOAP message.
    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'>" +
    " <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>account</q1:EntityName>" +
    "   <q1:ColumnSet xsi:type='q1:ColumnSet'>" +
    "     <q1:Attributes>" +
    "     <q1:Attribute>new_supportlevel</q1:Attribute>" +
    "     </q1:Attributes>" +
    "   </q1:ColumnSet>" +
    "   <q1:Attributes>" +
    "     <q1:Attribute>accountid</q1:Attribute>" +
    "   </q1:Attributes>" +
    "   <q1:Values>" +
    "     <q1:Value xsi:type='xsd:string'>" + strAccountID + "</q1:Value>" +
    "   </q1:Values>" +
    "  </query>" +
    " </soap:Body>" +
    " </soap:Envelope>";
    
    //DEBUG: alert("Message to send:\n\n" + xml);
    
    //Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    
    //DEBUG: alert("Capture the result ...");
    
    //Capture the result.
    var resultXml = xHReq.responseXML;
    //DEBUG: alert("ResultXml.xml: \n" + resultXml.xml);
    
      //Check for errors.
      var errorCount= resultXml.selectNodes('//error').length;
    
      //DEBUG: alert("Test error value...");
      if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        //alert(msg);
        //alert(resultXml.xml);
      } else {
        if (resultXml.selectSingleNode("//new_supportlevel") != null) {
    
          //GET THE ACCOUNT NAME -- DEBUG ONLY -- Requires this additional attribute in SOAP Request: "<q1:Attribute>name</q1:Attribute>" +
          //var strAcctName= resultXml.selectSingleNode("//name").nodeTypedValue;
          //alert(strAcctName);
    
          //DEBUG: alert("getAttribute 'new_supportlevel' ...");
          var strSupportLevel = resultXml.selectSingleNode("//new_supportlevel").getAttribute("name");
          //DEBUG: alert("Support Level: " + strSupportLevel);
    
          crmForm.all.new_supportlevel.DataValue = strSupportLevel;
    
        } else {
          //DEBUG: alert("The attribute 'new_supportlevel' has no value, or was not returned.");
          crmForm.all.new_supportlevel.DataValue = "NULL"
        }
    
      }
    

    Monday, November 08, 2010 8:23 PM
  • To quote Michael Bolton, of OfficeSpace: "I always forget some mundane detail like that!"
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, November 08, 2010 8:28 PM