Announcements
How do I make calls to custom actions from PCF ? Any suggestions , please help.
Thanks
You will need to use the WebApi.execute method to call the action.
Here is a sample I wrote for the Xrm.WebApi - but it's the same for the context.WebApi in PCF - https://github.com/scottdurow/PowerApps-Samples/blob/model-driven-app-webapi/cds/webapi/ts-model-driven-app/src/test/Actions/WinOpportunity.ts
Hope this helps,
Scott
Thanks Scott . Initially I thought of the same.
As per latest documentation it looks like only 5 methods are only supported and in VS code those 5 methods are only showing.
https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/webapi
Please suggest if that still holds true.
execute and executeMultiple is still there on the webApi object - it is just not exposed by the Typescript defintions in PCF.
I suspect this is the case because it doesn't necessarily match up with the direction that PCF is going when embeded in CanvasApps.
@HemantGCould you comment on this? Is Xrm.WebApi.execute specifically not supported in PCF even if it is part of the Xrm.WebApi in Model driven apps? If this is the case then it'll be a problem for converting Webresources over to PCF.
You can revert to just calling the Web API via fetch if it's not implemented yet. While not as 'nice' as using the webAPI wrapper, it's supported and does the job.
This example calls the "WinOpportunity" action as documented in https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/use-web-api-actions
const query = "/api/data/v9.0/WinOpportunity"; const headers = { "Accept": "application/json", "Content-Type": "application/json; charset=utf-8", "OData-MaxVersion": "4.0", "OData-Version": "4.0" } const opportunityId = "(b3828ac8-917a-e511-80d2-00155d2a68d2)" const body = JSON.stringify( { "Status": 3, "OpportunityClose": { "subject": "Won Opportunity", "opportunityid@odata.bind": "/api/data/v9.0/opportunities" + opportunityId } } ) await fetch(query, { method: 'post', headers: headers, body: body });
You may need to polyfill fetch for internet explorer though as using XmlHttpRequest is just ugly.
Hi Nick,
Thanks for replying on this. before proceeding wanted to know if this is working for you ? As per latest MSDN and earlier post suggested by Scott it should work but to confirm if this is working for you ?
Hey ManishJain,
The .execute and .executeMultiple do work for me, they are there on the webAPI object in the browser, but not in the typescript definitions or the documentation at the moment, so they are technically not supported.
The webAPI is just a wrapper around the actual Web Api though, which you can call via XmlHttpRequest or Fetch. So if you want to do this in a supported manner, you could just call the Web Api yourself instead of using the not yet documented or supported execute method on the webAPI object.
Please share the link/code
@NickDewitt wrote:Hey ManishJain, The .execute and .executeMultiple do work for me, they are there on the webAPI object in the browser, but not in the typescript definitions or the documentation at the moment, so they are technically not supported. The webAPI is just a wrapper around the actual Web Api though, which you can call via XmlHttpRequest or Fetch. So if you want to do this in a supported manner, you could just call the Web Api yourself instead of using the not yet documented or supported execute method on the webAPI object.
to your working solution
I shared it in the first post, that's an example of calling the WinOpportunity action using fetch, and I linked to the documentation supporting it..
If we are talking about webapi calls to actions this is the code we use using XMLHttpRequest.
private async getLicence(product:string): Promise<any>{ var id= Xrm.Utility.getGlobalContext(); var parameters = { ProductName : product }; var req = new XMLHttpRequest(); return new Promise(function (resolve, reject) { req.open("POST", id.getClientUrl() + "/api/data/v9.0/hdn_ValidateLicence", true); req.onreadystatechange = function () { if (req.readyState !== 4) return; if (req.status >= 200 && req.status < 300) { // If successful try { var result=JSON.parse(req.response); if (parseInt(result.StatusCode)<0){ reject({ status: result.StatusCode, statusText: result.StatusMessage }); } resolve(req.response); } catch (error){ throw error; } } else { // If failed reject({ status: req.status, statusText: req.statusText }); } }; 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.send(JSON.stringify(parameters)); }); }
I'm unable to call a custom action following the ms documentation on using custom actions and this thread. The following is my query I append to the url:
const query = `/api/data/v9.0/incidents(${this._entityId})/Microsoft.Dynamics.CRM.my_CustomAction`;
I'm now getting this error:
{"error":{"code":"","message":"No HTTP resource was found that matches the request URI 'https://XXX.crm4.dynamics.com/api/data/v9.0/incidents(1234567890)/Microsoft.Dynamics.CRM.my_CustomAction'."}}
What am I missing?
let response = await fetch(query, { method: 'post', headers: headers, body: body });
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.
Congratulations to our community stars!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
WarrenBelz 421 Most Valuable Professional
11manish 153 Super User 2026 Season 2
MS.Ragavendar 116 Super User 2026 Season 2