Call Workflow in CRM 2015 Easily from JavaScript Library

Posted: August 13, 2015 in Dynamics CRM 2013, Dynamics CRM 2015, JavaScript

In the past if you’ve needed to call a workflow from JavaScript, you need to build a massive XML SOAP request making sure to pass in the correct attributes and conditions to get the request working.

This is tedious and messy, especially when there are many places you need to do this in a solution. It’s also not good if something breaks in the future and you need to go back and fix up all instances of where the code is being used.

For these reasons, I’ve created a JavaScript library to simplify calling processes, and to make the code manageable going forward. But most of all, it’s so I don’t have to keep finding the correct way to build the SOAP requests!

This library includes functions for calling workflows, actions, and even popping dialogs. For this blog post, I’ll just look at calling workflows. I’ll cover calling actions and dialogs in other posts.

To download the JavaScript library, check out the project on CodePlex: https://processjs.codeplex.com/

Call Workflow

Runs the specified workflow for a particular record asynchronously. Optionally, you can add callback functions which will fire when the workflow has been executed successfully or if it fails.

Parameters: Workflow ID/Guid, Record ID/Guid, Success Callback (function), Error Callback (function), CRM Base URL (not required on forms/views)

Process.callWorkflow("4AB26754-3F2F-4B1D-9EC7-F8932331567A", 
    Xrm.Page.data.entity.getId(),
    function () {
        alert("Workflow executed successfully");
    },
    function () {
        alert("Error executing workflow");
    });
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s