Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

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

  • Prem27 Profile Picture
    Prem27 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.

  • Verified answer
    Aman Kothari Profile Picture
    Aman Kothari 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
    Prem27 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.

  • Suggested answer
    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));

  • Verified answer
    Aman Kothari Profile Picture
    Aman Kothari 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 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans