Trigger a cloud flow on a button click 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 ...
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 wh...
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...
How do I trigger a logic that is common across the entities contained in a cloud flow on a button click?
A few common ways:
Having a HTTPS trigger flow
Creating a 'Trigger' field on the entities
Potential drawbacks:
Having a HTTPS trigger would mean we need to also secure it, adding a trigger field on the entity is also a good option but we may end up creating a whole lot of fields to trigger the same flow across different entities.
Proposed solution:
To use the 'When an action is performed' dataverse trigger.

Idea :
A custom API that is unbound
Create a custom API, that takes the record id and any required field as input parameters. These parameters can then be passed over to the cloud flow.
A javascript web resource that can execute the custom API
This javascript code would execute the custom API on clicking a custom button that will then trigger the cloud flow.
A child flow that has a common logic that can be used across
Having the commonly used logic inside a cloud flow helps in reusability.
All the above components can be reused and do not require to be re-created.
Note : There is also a possibility that the entire logic in the child flow could be moved to custom api itself, but there could be many such child flows, that would mean a developer write the code and unit test it and also involves significant development efforts.The idea is to make use of low code solution that could use to trigger the logic in various child flows
Below are some of the screen grabs that could help design a solution based on the proposed idea.
Here is how the custom API looks


For the code to execute, customize the ribbon using the ribbon workbench, add a button then create a new command and add the script and pass the parameter
Crm Parameter = PrimaryControl

Sample javascript code in the web resource would look like below.
function executeCalculateWorkingDays(primaryControl) {
var recordId = primaryControl.data.entity.getId().replace(/[{}]/g, "");
var execute_sh_calculateworkingdays_Request = {
// Parameters
EntityId: recordId, // Edm.Guid
getMetadata: function () {
return {
boundParameter: null,
parameterTypes: {
EntityId: { typeName: "Edm.Guid", structuralProperty: 1 }
},
operationType: 0,
operationName: "sh_calculateworkingdays"
};
}
};
Xrm.WebApi.online.execute(execute_sh_calculateworkingdays_Request)
.then(function success(response) {
if (response.ok) {
console.log("Success");
}
})
.catch(function (error) {
console.log(error.message);
});
}
Here is how the child flow can be called as a step in the main flow
