Call Custom Actions in Dataverse using Web API – Quick Recap

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..

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


Discover more from ECELLORS CRM Blog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Pavan Mani Deep Y

Passionate for Power Platform. A technology geek who loves sharing the leanings, quick tips and new features on Dynamics 365 & related tools, technologies. An Azure IOT and Quantum Computing enthusiast...

Leave a comment

Discover more from ECELLORS CRM Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading