Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Call a global custom actiob by javascript without using any guid

Posted on by 270

Hello,

I want to call a global action by javascript using web api, How can I do it without using any record Id

Below is my code: 

var query = "emails(" + parent.Xrm.Page.data.entity.getId().replace('{', '').replace('}', '') + ")/Microsoft.Dynamics.CRM.myCustomActionName";
var req = new XMLHttpRequest();
req.open("POST", parent.Xrm.Page.context.getClientUrl() + "/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 () {
.........


*This post is locked for comments

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Call a global custom actiob by javascript without using any guid

    Take a look at the article below:

    debajmecrm.com/.../dynamics-crm-web-api-action-execute

    The article focuses on doing this with a Guid, but at the end it says, if you want to execute this without a Guid:

    orgname.crm.dynamics.com/.../new_TestAction

    Also, I would download the CRM Rest Builder (latest version), and there you have an option to select Action as the type of Action. If you don't select a Primary Entity, it will display the list of Global Actions that you can use, and will build the code for you.

    Hope this helps.

  • EnriqueMdz Profile Picture
    EnriqueMdz 1,065 on at
    RE: Call a global custom actiob by javascript without using any guid

    Hi Don Salazar, hope you're doing good.

    Global Actions doesn't require any GUIDs as this is only for actions that are directly related to an specific entity. Make sure your action is global and that you're sending the mandatory parameters that is expecting(If any). If it is not expecting any extra parameters the call should be succesfull.

    Example:

            var RequestXml = "<s:Envelope xmlns:s='schemas.xmlsoap.org/.../envelope'>";
            RequestXml += "<s:Body>";
            RequestXml += "<Execute xmlns='schemas.microsoft.com/.../Services'>";
            RequestXml += "<request xmlns:b='schemas.microsoft.com/.../Contracts' xmlns:i='www.w3.org/.../XMLSchema-instance'>";
            RequestXml += '<b:Parameters xmlns:c="schemas.datacontract.org/.../System.Collections.Generic">';
            RequestXml += '</b:Parameters>';
            RequestXml += '<b:RequestId i:nil="true"/>';
            RequestXml += '<b:RequestName>ACTION_NAME</b:RequestName>';
            RequestXml += '</request>';
            RequestXml += '</Execute>';
            RequestXml += '</s:Body>';
            RequestXml += '</s:Envelope>';
    
            var serverUrl = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web";
            var req = new XMLHttpRequest();
            req.open("POST", serverUrl, 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.onreadystatechange = function () { YOUR_CALLBACK_METHOD };
            req.send(RequestXml);


    Just change the ACTION_NAME & YOUR_CALLBACK_METHOD constants for your desired values and you should be good to go.

    Please make mark this answer as verified if helpfull.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans