We had once given an option to one of our customers to perform an action using on-demand workflow. We provided them with the steps to run the workflow from the “Run Workflow…” button that is added to the entity in case and entity has on-demand workflows published against them.
The customer however wanted that we add a button with a descriptive lable that performed the job so that the users are not burdened with having to select the correct workflow from the list and it was a one-click solution.
We found that CRM has an inbuilt function made available that calls the workflow “launchOnDemandWorkflow”
The syntax of the function is
launchOnDemandWorkflow(‘crmGrid’,ObjectTypeCode,Workflow ID) //when called from grid
launchOnDemandWorkflow(”,ObjectTypeCode,Workflow ID) //when called from entity form
This function has 3 parameters.
The first one is left blank only if the button is on the record of that entity and workflow needs to be called on that record only. whereas, if the button is placed on the grid of CRM entity view then first parameter should be ‘crmGrid‘ so that the workflow will get called for the records selected in that view.
Second parameter contains object type code of that entity
Third parameter is the id of the workflow to be fired
To get the workflow id, follow the below steps.
1. Go to Setting –> Workflow form.
2. Here open the workflow that you want to run on button click.
3. Now press “Ctrl + N” which will open the same page in the IE.
4. In the Address bar of IE you can find the id of workflow.
This should help provide users with the most familiar option of clicking a button to perform an action.