Launch a CRM Workflow Dialog from a Ribbon Button

A common requirement from many customers is how to launch a Workflow Dialogue, that will collect and process information, using step-by-step scripts to direct users through a process.

Using the Ribbon Editor, you create a button, give it a fancy image (that should be uploaded as a web resource) and point it to your javascript function that will launch the new CRM workflow dialogue.

ribbon

Here’s the code that will launch my new Dialog and refresh the page once the Dialog is closed.

function LaunchCrmWorkflowDialog(dialogId, entityName, entityId, refreshWindow) {
    var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    window.showModalDialog(serverUri + '?DialogId=' + dialogId + '&EntityName=' + entityName + '&ObjectId=' + entityId, null, 'dialogHeight:600px;dialogWidth:600px;resizable=1;status=1;scrollbars=1');
    if (refreshWindow)
        window.location.reload(true);
}

function GetCurrentRecordId() {
    return Xrm.Page.data.entity.getId();
}

function CancelClass() {
    LaunchCrmWorkflowDialog("{BAAF2F58-21C1-4275-8FF5-C357931727DF}", "ecs_class", GetCurrentRecordId(), true);
}