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

Start Transitioning your Dynamics 365 Client Applications to use Dataverse Client

Hi Folks,

This blog post deals about what you need to do for your client applications in specific to use Dataverse Client API instead of existing CrmServiceClient(Core Assemblies) API.

Below were 3 reasons cited by Microsoft and why we need to just be aware of this move.

1.Cross Platform Application Support: With the introduction of Microsoft.PowerPlatform.Dataverse.Client, the new Dataverse Service Client supports Cross Platform Support.

2. MSAL Authentication: New Dataverse ServiceClient API uses MSAL while our older CrmServiceClient API uses ADAL. ADAL.Net is no longer supported.

3. Performance and functional benefits: We can have one authentication handler per web service connection instead of just one per process. The Dataverse Service Client class supports a smaller interface surface, inline authentication by instance, and Microsoft.Extensions.Logging.ILogger.

What’s the impact?

  • Plug-ins or custom workflow activities – no changes
  • New or existing online applications – changes are needed but not immediately…
  • On-premises applications – this article is not for you, yet

So, meaning it impacts Online Client applications only. While you really don’t need to worry much about this the class member signatures of ServiceClient and CrmServiceClient are the same, except for the class names themselves being slightly different. Application code should not need any significant changes.

As of now, no changes to your code are required, but it is better to keep in mind that in the future the CRM 2011 Service End Point would be deprecated, and this change would be made mandatory.

So, what should you do to incorporate this change?

Use the following assemblies from Nuget instead of CrmSdk.CoreAssemblies

Add the below using statement to use Microsoft.PowerPlatform.Dataverse.Client

Use ServiceClient instead of CrmServiceClient, ServiceClient would return your OrganizationService.

Instead of

Be strategic to minimize the impact to your apps.

Cheers,

PMDY