there are many solutions to do this functionality but I am going to describe the easiest way.
The following solution demonstrates adding a 'short-cut' to a Workflow already created on to the form and grids. The Grid button will run a workflow on the selected records.
Here is the step by step solutions.
1) create a workflow that you want to run and set "As an on-demand process" option.
after the workflow is created copy the workflow GUID URL as shown in the below image.
2) Now create a button on your custom or out of the box entity using ribbon workbench.
or just drag and drop the button where you want to add.
3) create a new command and then click "add action" select "Javascript action" from the dropdown.
4) In the library option select JS file name and in the function name field add your function name.
in my case js file name is new_script and the function name is workflow.
5) Now click add parameters and then select CRM parameters:
6) select Primary control by id.
Click Save and Publish.
Here is the complete code Javascript Code:
function Workflow() {
var features =
"toolbar=no, scrollbars=yes, resizable=no, top=120, left=350, width=600px,
height=500px";
var url =
Xrm.Page.context.getClientUrl() +
"/cs/dialog/rundialog.aspx?DialogId=%7bF977BEAB-1BE0-4150-A9CE-07CEFB4A6147%7d&EntityName=opportunity&ObjectId="
window.open(url,
"_blank", features, false);
}
Thanks.