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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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 ....

I have the same question (0)
  • Suggested answer
    Henry J. Profile Picture
    5,237 on at

    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Subra Profile Picture

Subra 118

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 89 Super User 2026 Season 1

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 85 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans