locked
Execute Action from JavaScript - Fails RRS feed

  • Question

  • I have created an Action (new_proc_kalle_anka_qwe) with no in or out parameters. Its set to Lead.

    I have used the SOAPLogger, where the request works and I get a successfull respons. I added the request generated from the SOAPLogger to JavaScript:

    ExecuteAction : function()

     var request = [];
     
     request.push("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>");
     request.push("<s:Body>");
     request.push("<Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>");
     request.push("<request i:type='b:new_proc_kalle_anka_qweRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/xrm/2011/new/'>");
     request.push("<a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>");
     request.push("<a:KeyValuePairOfstringanyType>");
     request.push("<c:key>Target</c:key>");
     request.push("<c:value i:type='a:EntityReference'>");
     request.push("<a:Id>388e09b6-7969-e411-80d6-00155d284700</a:Id>");
     request.push("<a:LogicalName>lead</a:LogicalName>");
     request.push("<a:Name>asd</a:Name>");
     request.push("</c:value>");
     request.push("</a:KeyValuePairOfstringanyType>");
     request.push("</a:Parameters>");
     request.push("<a:RequestId i:nil='true' />");
     request.push("<a:RequestName>new_proc_kalle_anka_qwe</a:RequestName>");
     request.push("</request>");
     request.push("</Execute>");
     request.push("</s:Body>");
     request.push("</s:Envelope>");

            var req = new XMLHttpRequest();
            req.open("POST", "http://localhost/xxx/XRMServices/2011/Organization.svc/web", true);       
            req.setRequestHeader("Accept", "application/xml, text/xml, */*");
            req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
            req.onreadystatechange = function () { assignResponse(req, successCallback, errorCallback); };

            // Run the action
            req.send(request.join(""));
    },
    assignResponse: function (req, successCallback, errorCallback) {       
            if (req.readyState == 4) {
                req.onreadystatechange = null; // Avoids memory leaks
                if (req.status == 200) {
                    if (successCallback != null) {
                        successCallback();
                    }
                }
                else {
                    errorCallback(req.responseXML);
                }
            }
    }

    The respons I get is:

    "<s:Envelope xmlns:s=\"<faultcode">http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><s:Fault><faultcode xmlns:a=\"a:DeserializationFailed</faultcode><faultstring">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher\">a:DeserializationFailed</faultcode><faultstring xml:lang=\"sv-SE\">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 361. Element 'http://schemas.microsoft.com/xrm/2011/Contracts/Services:request' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/2011/new/:new_proc_kalle_anka_qweRequest'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'new_proc_kalle_anka_qweRequest' and namespace 'http://schemas.microsoft.com/xrm/2011/new/'.'.  Please see InnerException for more details.</faultstring></s:Fault></s:Body></s:Envelope>"

    Anyone resolved this issue?

    Tuesday, November 11, 2014 9:11 AM

Answers

  • Found the issue.

    This:
    request.push("<request i:type='b:new_proc_kalle_anka_qweRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/xrm/2011/new/'>");

    Should simply be:
    request.push("<request xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>");

    • Marked as answer by Marten Rading Wednesday, November 12, 2014 7:37 AM
    Wednesday, November 12, 2014 7:37 AM

All replies

  • Found the issue.

    This:
    request.push("<request i:type='b:new_proc_kalle_anka_qweRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/xrm/2011/new/'>");

    Should simply be:
    request.push("<request xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>");

    • Marked as answer by Marten Rading Wednesday, November 12, 2014 7:37 AM
    Wednesday, November 12, 2014 7:37 AM
  • Thanks Marten!  I was having an identical problem, which I'd spent an entire day trying to solve.  Your solution works perfectly.
    Wednesday, April 1, 2015 2:55 PM