Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to get Output Parameter from Custom Action Using Web API

Posted on by 145

I am unclear as to how to get output parameters using Web Api for custom actions.

I have created a custom action that creates an email with an attached report, and then returns EmailId as an output parameter.

pastedimage1631569115500v1.png

I assign the returned email ID to the local output parameter.

pastedimage1631569196602v2.png

I call the action using web api.


function CallAction() {
var regNumber = Xrm.Page.getAttribute("xxxxxxxxxxxxxxxxxxxr").getValue();
var Id = Xrm.Page.data.entity.getId().substring(1, 37);
var serverURL = Xrm.Page.context.getClientUrl();
var emailid="";
var parameters = {};
parameters.ReferenceNumber = regNumber;
parameters.ReportName = "Test";
console.log(Id);
var req = new XMLHttpRequest();
req.open("POST", serverURL + "/api/data/v8.2/xxxxxxxxxxxxxxxx(" + Id + ")/Microsoft.Dynamics.CRM.xxxxxxxxxxxxxxxxxxxxx", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 200) {
var results = JSON.parse(this.response);
if(results==null)
console.log("Results null");
else
{
console.log("Results NOT null");
console.log(this.response);
}

}
else
{
Xrm.Utility.alertDialog(this.statusText);
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
};
req.send(JSON.stringify(parameters));

}

I get null for EmailID in the response body.

pastedimage1631569317595v4.png

Is this not the correct approach?

Thanks

ngetz

  • ngetz Profile Picture
    ngetz 145 on at
    RE: How to get Output Parameter from Custom Action Using Web API

    I got it to work as a plugin, thank you.

  • ngetz Profile Picture
    ngetz 145 on at
    RE: How to get Output Parameter from Custom Action Using Web API

    Prawin,

    In your blog example you are using a plugin. I have a custom workflow with output parameters and then the action pulls the output parameters. Will it work with a custom workflow?

    Thanks

  • ngetz Profile Picture
    ngetz 145 on at
    RE: How to get Output Parameter from Custom Action Using Web API

    I will take a look, thanks.

  • Verified answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: How to get Output Parameter from Custom Action Using Web API

    It may help you, please refer this blog.

    pravinpawarweb.wordpress.com/.../

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans