cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pradeepperi
Level: Powered On

Calling a Custom Action

Is it possible to call a custom action from the PCF control? Execute function shows in the WebAPI object  but when we call a custom action an error message is thrown saying that Execute is undefined. 

1 REPLY 1
Highlighted
ben-thompson
Level 8

Re: Calling a Custom Action

	private async callAction(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/actionName", 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));
		});	
	}

Is the code we use for checking if the user's licence is valid - it uses a promise that returns resolve or reject as appropriate (and we actually only care about rejects here).

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 52 members 4,263 guests
Please welcome our newest community members: