Hi Folks,
Here is how you can quickly call action using Web API, with this method you can execute a single action, function, or CRUD operation. In the below example, let’s see how you can call an action. Here is function…to achieve this..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var formContext = executionContext.getFormContext(); | |
| var message = "Please enter a valid NRIC Number"; | |
| var uniqueId = "nric_valid"; | |
| var NRIC = formContext.getAttribute("new_nric").getValue(); | |
| if(NRIC !== null) | |
| { | |
| var execute_ValidateNRIC = { | |
| NRIC: NRIC, // Call this function only when NRIC value which is non-null | |
| getMetadata: function () { | |
| return { | |
| boundParameter: null, | |
| parameterTypes: { | |
| NRIC: { typeName: "Edm.String", structuralProperty: 1 } | |
| }, | |
| operationType: 0, | |
| operationName: "new_ValidateNRIC", | |
| outputParameterTypes: { | |
| IsValid: { typeName: "Edm.Boolean" } | |
| } | |
| }; | |
| } | |
| }; | |
| Xrm.WebApi.execute(execute_new_ValidateNRIC).then( | |
| function success(response) { | |
| if (response.ok) { | |
| response.json().then(function (data) { | |
| if (!data.IsValid) { | |
| formContext.getControl("new_nric").setNotification(message, uniqueId); | |
| } else { | |
| formContext.getControl("new_nric").clearNotification(uniqueId); | |
| } | |
| }).catch(function (error) { | |
| Xrm.Navigation.openAlertDialog("Error occured from Validate NRIC "+error); | |
| }); | |
| } | |
| } | |
| ).catch(function (error) { | |
| Xrm.Navigation.openAlertDialog(error.message); | |
| }).catch(function (error) { | |
| Xrm.Navigation.openAlertDialog(error.message); | |
| }); | |
| } | |
| } |
This example details with Unbound action, which is not tagged to any entity, however if in case on Bound action, you will specify the entity name for bound parameter instead of null. You need to specify the Metadata accordingly for your Action. Let’s understand it’s syntax first…
Xrm.WebApi.online.execute(request).then(successCallback, errorCallback);
Parameters
Share this:
- Click to share on X (Opens in new window) X
- Click to share on Facebook (Opens in new window) Facebook
- Click to email a link to a friend (Opens in new window) Email
- Click to share on WhatsApp (Opens in new window) WhatsApp
- Click to share on LinkedIn (Opens in new window) LinkedIn
- Click to share on Telegram (Opens in new window) Telegram




