Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Unanswered

Calling a Custom Action

(0) ShareShare
ReportReport
Posted on by 8

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. 

  • Ben Thompson Profile Picture
    1,400 on at
    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).

     

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 65 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 55 Super User 2025 Season 1

Overall leaderboard