web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

internal server error (status code:500) while calling an ACTION using SOAP envelope.

(0) ShareShare
ReportReport
Posted on by 370

hullow to all,

i'm trying to call an action using soap request. but i get an internal server error.

can anybody suggest why is this happening. i'm posting the snapshot of code and action.code1stpart.pngcode2ndpart.pngcode3rdpart.png1440.action.png4263.script-error.png

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aman Kothari Profile Picture
    on at
    RE: internal server error (status code:500) while calling an ACTION using SOAP envelope.

    Hi,

    After looking your screenshots ,SOAP Request is missing Target KeyValuePair.

    Please find below code for execute action using JS.

    var requestXML = ""
    requestXML += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
    requestXML += " <s:Body>";
    requestXML += " <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";
    requestXML += " <request xmlns:a=\"schemas.microsoft.com/.../Contracts\">";
    requestXML += " <a:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";
    requestXML += " <a:KeyValuePairOfstringanyType>";
    requestXML += " <b:key>Target</b:key>";
    requestXML += " <b:value i:type=\"a:EntityReference\">";
    requestXML += " <a:Id>" + EntityGuid + "</a:Id>";
    requestXML += " <a:LogicalName>" + EntityName + "</a:LogicalName>";
    requestXML += " <a:Name i:nil=\"true\" />";
    requestXML += " </b:value>";
    requestXML += " </a:KeyValuePairOfstringanyType>";
    requestXML += " </a:Parameters>";
    requestXML += " <a:RequestId i:nil=\"true\" />";
    requestXML += " <a:RequestName>" + RequestName + "</a:RequestName>";
    requestXML += " </request>";
    requestXML += " </Execute>";
    requestXML += " </s:Body>";
    requestXML += "</s:Envelope>";
    var req = new XMLHttpRequest();
    req.open("POST", GetClientUrl(), false)
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
    req.send(requestXML);
    if (req.status == 200) {
    var response = req.responseXML.xml;
    }

    Hope it'll help you.

    Thanks

    Aman Kothari

    Blog  LinkedIn 

  • Suggested answer
    Morne Wolfaardt Profile Picture
    on at
    RE: internal server error (status code:500) while calling an ACTION using SOAP envelope.

    There is a much easier way to call actions from javasript

      var organizationUrl = Xrm.Page.context.getClientUrl();
                        var data = {

                            "Assign": true,
                            "RemoveFromQueue": true,
                            "TargetItemObjectTypeCode": "112"
                        };
                     
                        var query = "queues(" + queueid + ")/Microsoft.Dynamics.CRM.new_GetNextCaseFromQueue";
                        var req = new XMLHttpRequest();
                        req.open("POST", organizationUrl + "/api/data/v8.0/" + query, true);
                        req.setRequestHeader("Accept", "application/json");
                        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                        req.setRequestHeader("OData-MaxVersion", "4.0");
                        req.setRequestHeader("OData-Version", "4.0");
                        req.onreadystatechange = function () {
                            if (this.readyState == 4) {
                                req.onreadystatechange = null;
                                if (this.status == 200) {
                                    var caseId = JSON.parse(this.response).ItemId;
                        // do stuff
                                } else {
                                    var error = JSON.parse(this.response).error;
                                    alert(error.message);
                                }
                            }
                        };
                   
                        req.send(window.JSON.stringify(data));

  • Prem27 Profile Picture
    370 on at
    RE: internal server error (status code:500) while calling an ACTION using SOAP envelope.

    Process-Session-Workflow-_2D00_-Microsoft-Dynamics-CRM-_2D00_-Google-Chrome_5F00_2016_2D00_01_2D00_19_5F00_11_2D00_04_2D00_50.png

    what does this error mean, i don't understand.

  • Verified answer
    Aman Kothari Profile Picture
    on at
    RE: internal server error (status code:500) while calling an ACTION using SOAP envelope.

    Hi,

    You are trying to cast EntityRefrence into Entity. Can you please post your code here ?

    Thanks

  • Prem27 Profile Picture
    370 on at
    RE: internal server error (status code:500) while calling an ACTION using SOAP envelope.

    yes Aman, you are right, actually i guess we can only pass entity reference and can't pass an entity through an action and the code i was trying to execute had and required an entity as i had to perform a change on one of it's attributes but i was casting an entity reference to an entity that's why invalid cast exception occured. so later i changed the code and cast it to entity reference and then retrieved it's attributes in a entity using entity reference's  id,columns and logical name. and it worked.

    thanks a lot for your guidance and support.

    looking forward for further association over the community platform.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Wayne Walton Profile Picture

Wayne Walton 2

#2
Good.Panos Profile Picture

Good.Panos 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans