Use tag parameter to bypass plugin execution in dynamics 365
Learning dynamics 365, Azure and Power Platform
Search for a command to run...
Learning dynamics 365, Azure and Power Platform
No comments yet. Be the first to comment.
Currently there is no straight forward way to open a canvas apps from the ribbon button unlike the custom page that can be opened using the Xrm.Navigation.navigateTo(pageInput,navigationOptions).then(successCallback,errorCallback);Refer : navigateTo ...
This is a preview feature ; works for flows that are part of solution. The flow run history is now stored in the table 'flowrun' and can be queried to get the history. Enabling the functionality :To enable this navigate to https://admin.powerplatfor...
What is Dataverse AI Functions Dataverse Provides built in AI Functions that are preconfigured. They are ready to use and do not require any data for training. They help in streamlining and improving the process Different available AI Functions ...
The easiest way to identify the flows that trigger on a particular entity with its messages is to run a SQL query using the sql4cds tool in the xrmtoolbox. The table that has the information is callback registration, querying the call back registrati...
Tag parameter is a savior when it comes to situation where a particular plugin execution needs to be skipped.
Scenario - A custom api creates contact and also performs execution of certain logic. Also, there is a plugin that executes similar logic which is triggered when contact is created. This leads to conflict, as custom api & plugin both performs the execution of similar logic. At a stage when design can not be changed, arises a need to skip/bypass the execution of logic in plugin, there comes the 'Tag' parameter.
Tag parameter can be set in the request, inside the api and can be accessed using the sharedvariables inside a plugin.
API code
namespace CustomAPI{
public partial class CustomAPI : IPlugin
{
private IPluginExecutionContext context;
private IOrganizationServiceFactory serviceFactory;
private IOrganizationService organizationService;
private ITracingService tracingService;
private OrganizationServiceContext serviceContext;
public void Execute(IServiceProvider serviceProvider)
{
ExecuteAsync(serviceProvider).GetAwaiter().GetResult();
}
public async Task ExecuteAsync(IServiceProvider serviceProvider)
{
context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
organizationService = serviceFactory.CreateOrganizationService(context.UserId);
serviceContext = new OrganizationServiceContext(organizationService);
tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
contact createContact = new Contact(){
firstname = "Shayan",
lastname = "RS"
};
CreateRequest createRequest = new CreateRequest();
createRequest.Target = createContact;
createRequest.Parameters.Add("tag","ApiContact");
CreateResponse createResponse = (CreateResponse);
organizationService.Execute(createRequest);
}
}
}
Plugin Code
Have not written the detail plugin code, but just the syntax as follows
if(context.SharedVariables.ContainsKey("tag")){
string tagValue = context.SharedVariables["tag"].ToString();
if(tagValue == "ApiContact")
return;
}
this way once the tag is passed from the custom api, and when plugin accesses it, it can be used to skip the plugin execution.