CRM 2013 SOAP Request giving error on CRM For Tablets RRS feed

  • Question

  • I have a very simple SOAP request which is as follows 

    function changeRecordStatus(RECORD_ID,stateCode,statusCode) {
            // create the SetState request
            var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
            request += "<s:Body>";
            request += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
            request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
            request += "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
            request += "<a:KeyValuePairOfstringanyType>";
            request += "<c:key>EntityMoniker</c:key>";
            request += "<c:value i:type=\"a:EntityReference\">";
            request += "<a:Id>" + RECORD_ID + "</a:Id>";
            request += "<a:LogicalName>new_expenseheader</a:LogicalName>";
            request += "<a:Name i:nil=\"true\" />";
            request += "</c:value>";
            request += "</a:KeyValuePairOfstringanyType>";
            request += "<a:KeyValuePairOfstringanyType>";
            request += "<c:key>State</c:key>";
            request += "<c:value i:type=\"a:OptionSetValue\">";
            request += "<a:Value>"+stateCode+"</a:Value>";
            request += "</c:value>";
            request += "</a:KeyValuePairOfstringanyType>";
            request += "<a:KeyValuePairOfstringanyType>";
            request += "<c:key>Status</c:key>";
            request += "<c:value i:type=\"a:OptionSetValue\">";
            request += "<a:Value>"+statusCode+"</a:Value>";
            request += "</c:value>";
            request += "</a:KeyValuePairOfstringanyType>";
            request += "</a:Parameters>";
            request += "<a:RequestId i:nil=\"true\" />";
            request += "<a:RequestName>SetState</a:RequestName>";
            request += "</request>";
            request += "</Execute>";
            request += "</s:Body>";
            request += "</s:Envelope>";
            //send set state request
                type: "POST",
                contentType: "text/xml; charset=utf-8",
                datatype: "xml",
                url: Xrm.Page.context.getServerUrl() + "/XRMServices/2011/Organization.svc/web",
                data: request,
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                    XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
                success: function (data, textStatus, XmlHttpRequest) {
                error: function (XMLHttpRequest, textStatus, errorThrown) {

    This is used to Set State of a record and is working absolutely fine in CRM Online/OnPrem. However on the CRM for tablet I get an error $ is undefined. Can somebody please help with this?



    Tuesday, October 21, 2014 10:54 AM

All replies

  • I would suggest rewriting the script to use a standard XMLHttpRequest object and remove the JQuery dependency. Otherwise if you have a lot of scripts that require jquery then read on. 

    I dont have a lot of experience with the tablet app but if the jquery library is referenced on the form it might need an event to cause it to load, you could do this by adding an onload event pointing to the jquery web resource and doing something like isNaN for the function.  

    I generally try to avoid using jquery in CRM as much as possible, while CRM does use it internally and sometimes the $ object is there. it seems like you cant rely on it always being loaded so you would have to add your own jquery web resource and that adds more overhead to the form load for a little bit of functionality gain, of course depends on how you use it. 

    Tuesday, October 21, 2014 11:02 PM