locked
Converting CRM2011 to CRM2013 Web Resource FetchXML RRS feed

  • Question

  • Hi folks,

    I am converting a deployment from CRM2011 to CRM2013.  I have a number of WebResources on the OnChange events on forms that look up information on other entities, then populate the fields on the forms.

    In CRM2011, I modified sample code to use FetchXML to retrieve the records, and then use the XRM....SetValue method to set the fields.

    My problem is that the CRM Conversion is failing on my legacy SOAP declaration.

    Can someone please tell me if there is a different method to do this.  I have attached the code below.

    Any help is greatly appreciated!

    function fShipTo_OnChange() {
        //alert(   Xrm.Page.data.entity.attributes.get("sm_shippingrequestsid"));
    
        var Xxml = ''; // Declaring string variable
        var XxHReq = new ActiveXObject("Msxml2.XMLHTTP");
        XxHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        XxHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
        XxHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    
        var event = Xrm.Page.getAttribute("sm_shippingrequestsid").getValue();
        var eventid = event[0].id;
    
        if (event != null) {
            // Prepare variables for a contact to retrieve.
            //var contactid = "4696f8cb-9a1c-dd11-ad3a-0003ff9ee217";
            var authenticationHeader = GenerateAuthenticationHeader();
    
            // 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>sm_seminar</entityName>" +
                "<id>" + eventid + "</id>" +
                "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
                "<q1:Attributes>" +
                "<q1:Attribute>sm_sponsorid</q1:Attribute>" +
                "<q1:Attribute>sm_location</q1:Attribute>" +
                "<q1:Attribute>sm_hotel</q1:Attribute>" +
                "<q1:Attribute>sm_dl1</q1:Attribute>" +
                "<q1:Attribute>sm_dl2</q1:Attribute>" +
                "<q1:Attribute>sm_dl3</q1:Attribute>" +
                "<q1:Attribute>sm_dl4</q1:Attribute>" +
                "<q1:Attribute>sm_dl5</q1:Attribute>" +
                "<q1:Attribute>sm_dl6</q1:Attribute>" +
                "</q1:Attributes>" +
                "</columnSet>" +
                "</Retrieve>" +
                "</soap:Body>" +
                "</soap:Envelope>";
    
            // Prepare the xmlHttpObject and send the request.
            var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
            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.setRequestHeader("Content-Length", xml.length);
            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);
            }
    

    Monday, August 25, 2014 1:45 PM

Answers

  • I end up converting all the code using the XrmSvcToolkit.  

    I used the  XrmSvcToolkit.retrieve retrieve method.  


           eventid = eventid.replace('{', '').replace('}', '');
    
            var results = XrmSvcToolkit.retrieve({
                entityName: "sm_seminar",
                id: eventid,
                select: ["sm_name",
                            "sm_SponsorId" ,
                            "sm_Location" ,
                            "sm_Hotel" ,
                            "sm_DL1" ,
                            "sm_DL2" ,
                            "sm_DL3" ,
                            "sm_DL4" ,
                            "sm_DL5" ,
                            "sm_DL6" 
                ],
                async: false
            });

    Note that I had to remove the braces ({  }) from GUID.

    Be careful when retrieving ID (GUID) fields.  To access GUID fields you need to use the .ID property (results.[name of field].Id)

    alert(results.sm_SponsorId.Id);
    • Marked as answer by PCR985 Friday, August 29, 2014 3:09 PM
    Friday, August 29, 2014 3:09 PM

All replies

  • You will need to update to the new web services endpoint, for starters: http://msdn.microsoft.com/en-us/library/gg309401.aspx

    The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.

    Monday, August 25, 2014 3:11 PM
  • I end up converting all the code using the XrmSvcToolkit.  

    I used the  XrmSvcToolkit.retrieve retrieve method.  


           eventid = eventid.replace('{', '').replace('}', '');
    
            var results = XrmSvcToolkit.retrieve({
                entityName: "sm_seminar",
                id: eventid,
                select: ["sm_name",
                            "sm_SponsorId" ,
                            "sm_Location" ,
                            "sm_Hotel" ,
                            "sm_DL1" ,
                            "sm_DL2" ,
                            "sm_DL3" ,
                            "sm_DL4" ,
                            "sm_DL5" ,
                            "sm_DL6" 
                ],
                async: false
            });

    Note that I had to remove the braces ({  }) from GUID.

    Be careful when retrieving ID (GUID) fields.  To access GUID fields you need to use the .ID property (results.[name of field].Id)

    alert(results.sm_SponsorId.Id);
    • Marked as answer by PCR985 Friday, August 29, 2014 3:09 PM
    Friday, August 29, 2014 3:09 PM