Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

How to call a global Action in javascript, with one entity reference input parameter and one output parameter

(0) ShareShare
ReportReport
Posted on by 5

I have this global action with one entity-reference input parameter and one output parameter(string).

I need to call this using javascript

I used the following code - 

```

function CallGlobalCustomAction(executionContext) {
    
    if(!executionContext) {
        console.log("no execution context found");
        return;
    }

    var formContext = executionContext.getFormContext();
    if(!formContext) {
        console.log("no form context found");
        return;
    }

    //get the current organization name
    var serverURL = formContext.context.getClientUrl();

    //query to send the request to the global Action 
    var actionName = "osm_OSMActionTaskSendEmail251267fffe73ea11a811000d3a86b423"// Global Action Unique Name

    //set the current loggedin userid in to _inputParameter of the 
    var InputParameterValue = formContext.context.getUserId();
 
    //Pass the input parameters of action
    var data = {
        "entityType" : "systemuser",
        "id": InputParameterValue
    };

    //Create the HttpRequestObject to send WEB API Request 
    var req = new XMLHttpRequest();
    //Post the WEB API Request 
    req.open("POST"serverURL + "/api/data/v9.1/" + actionNametrue);
    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 /* complete */)
        {
            req.onreadystatechange = null;
           
            if (this.status == 200 || this.status == 204)
            {
                alert("Action Executed Successfully...");
                //You can get the output parameter of the action with name as given below
                result = JSON.parse(this.response);
                alert(result.Status);
               
            }
            else
            {
                var error = JSON.parse(this.response).error;
                alert("Error in Action: "+error.message);
            }
        }
    };
    //Execute request passing the input parameter of the action 
    req.send(window.JSON.stringify(data));
}

```

But this is throwing an error as in the ss - 

pastedimage1586073924872v2.png

This is the ss for my action - 

pastedimage1586074128232v3.png

What can be donw, or if someone can share me the proper code ....

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: How to call a global Action in javascript, with one entity reference input parameter and one output parameter

    Hello,

    Have you had a look at this documentation?

    This describes how to call unbound actions using the Web API:
    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/web-api-functions-actions-sample#bkmk_unboundActionWithParams

    Henry

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans