locked
updating a field using Userid through Soap,,, Working in IE not in Chrome RRS feed

  • Question

  • HI all,

               please find the code below to update Parentsystemuserid in a field through userid... the below code working fine in IE but not in Chrome.. Please Gide me to solve this.. am Getting Error in defaultrmvalue().. marked is the error please guide me 

    function form_onload()
    {
    defaultrmvalue();
    defaultrmvaluename();

    }


                function defaultrmvalue()
                {
    // Prepare variables for a contact to retrieve.
                    var userid = Xrm.Page.context.getUserId();
                    var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

    // 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'>"+ 
                    authenticationHeader+ 
                    "<soap:Body>"+ 
                    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
                    "<entityName>systemuser</entityName>"+ 
                    "<id>"+userid+"</id>"+ 
                    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ 
                    "<q1:Attributes>"+ 
                    "<q1:Attribute>parentsystemuserid</q1:Attribute>"+ 
                    "</q1:Attributes>"+ 
                    "</columnSet>"+ 
                    "</Retrieve>"+ 
                    "</soap:Body>"+ 
                    "</soap:Envelope>";
    // Prepare the xmlHttpObject and send the request.
                    var xHReq = new XMLHttpRequest();
                    xHReq.open("POST", "https://crmuat.hexaware.com/mscrmservices/2007/CrmService.asmx", false);
                    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
                    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    xHReq.send(xml);
    // Capture the result.
                    var resultXml = xHReq.responseXML;
    // Check for errors.
                    var errorCount = resultXml.selectNodes('//error').length;
                    if (errorCount != 0)
                    {

                      var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                         alert(msg);
                    }
    // Display and Assign default GUID to the field the retrieved value.
                    else
                    {
    var errorCount = resultXml.selectNodes('//q1:parentsystemuserid').length;
    if (errorCount != 0)
    {
    rmid = resultXml.selectSingleNode("//q1:parentsystemuserid").nodeTypedValue;
    }

                       //var  rmid= resultXml.selectSingleNode("//q1:parentsystemuserid").nodeTypedValue;
                        var lookupData = new Array();
                        var lookupItem= new Object();
                        lookupItem.id = rmid;
                        lookupItem.typename = 'systemuser';
                        lookupData[0] = lookupItem;
                        Xrm.Page.getAttribute("new_reportingmanagerid").setValue(lookupData);
                    }
                }

      function defaultrmvaluename()
                {
                    // Prepare variables for a contact to retrieve.
                    var userid = rmid;
    alert(userid);
                    var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();



                    // 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'>"+ 
                    authenticationHeader+ 
                    "<soap:Body>"+ 
                    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
                    "<entityName>systemuser</entityName>"+ 
                    "<id>"+userid+"</id>"+ 
                    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ 
                    "<q1:Attributes>"+ 
                    "<q1:Attribute>fullname</q1:Attribute>"+ 
                    "</q1:Attributes>"+ 
                    "</columnSet>"+ 
                    "</Retrieve>"+ 
                    "</soap:Body>"+ 
                    "</soap:Envelope>";
                    // Prepare the xmlHttpObject and send the request.
                   var xHReq = new XMLHttpRequest();
                    xHReq.open("POST", "/mscrmservices/2007/CrmService.asmx", false);
                    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
                    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    xHReq.send(xml);
                    // Capture the result.
                    var resultXml = xHReq.responseXML;

                    // Check for errors.
                    var errorCount = resultXml.selectNodes('//error').length;
                    if (errorCount != 0)
                    {
                         var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                         alert(msg);
                    }
                    // Display and Assign default GUID to the field the retrieved value.
                    else
                    {
    //Instead Of Node Type Value IN 2011 we should use this

    var errorCount = resultXml.selectNodes('//q1:fullname').length;
    if (errorCount != 0)
    {
    rmname= resultXml.selectSingleNode("//q1:fullname").nodeTypedValue;
    }


                        //rmname=resultXml.selectSingleNode("//q1:fullname").nodeTypedValue;
                        var lookupData = new Array();
                        var lookupItem= new Object();
                        lookupItem.id = rmid;
                        lookupItem.typename = 'systemuser';
                        lookupItem.name=rmname;
                        lookupData[0] = lookupItem;
                        Xrm.Page.getAttribute("new_reportingmanagerid").setValue(lookupData);
                    }
                }

    Monday, April 15, 2013 4:31 PM

Answers

  • With cross-browser the selectsinglenode does not work in Chrome.

    The sample code library provided in the SDK provides alternatives to use this

    The SDK.MetaData.js library found in Sample: Retrieve Entity Metadata
    Using JavaScript
    uses helper functions. This library uses the SOAP endpoint
    for web resources to retrieve entity and attribute metadata. This library
    depends on parsing data from the XML document returned as
    XMLHttpRequest.responseXML. In this library the following helper
    functions were added and used throughout the other functions in the library.

    With these helper functions the existing code that was written only for
    Internet Explorer was updated as shown:


    Original Internet Explorer Only Code New Function to Support Multiple Browsers

    node.selectNodes(XPathExpr);

    SDK.MetaData._selectNodes(node,XpathExpr);

    node.selectSingleNode(XPathExpr);

    SDK.MetaData._selectSingleNode(node, XPathExpr);

    node.selectSingleNode(ElementName).text;

    SDK.MetaData._selectSingleNodeText(node,
    ElementName);

    node.text

    SDK.MetaData._getNodeText(node);

    HTH

    Sam

     


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, April 16, 2013 8:32 AM