Dan Dan -4 years ago 352
Javascript Question

Start workflow with javascript in Dynamics CRM 2016

I need to create a JS-Library which can run workflow using new WebApi for Dynamics CRM 2016:



I need to start workflow from my Code. (workflow should be “real-time”) and not asynchronously . I will build my function-call into Ribbon on form.
If anyone can help me I would be more then thankful, since I searched all internet and could not found how to solve this, except from above link where I found this method



but I'm not sure how to use this method? Once agin it has to be “real-time”
I found solutions such as:

-https: //processjs.codeplex.com/

but this does not work for me since it run workflow asynchronously. It has to be using Web API from link provided above. I think that this Web API works only for Microsoft Dynamics 2016

Answer Source

Now that we have actions there really isn't a need to start a workflow from javascript anymore. I used to do so using a javascript library that used the SOAP api but the web api actions are much easier to use. And an action is created in the same way as a workflow. To create an action go to create a workflow but instead of choosing workflow from the dropdown select action. You will end up with a form like this. enter image description here Remember the unique name and the entity which you will run it against. In this example I'll be using this workflow pictured which runs against a contact record. From javascript I can now issue a POST to

https://<your-crm-server>/api/data/v8.0/contacts(<contact-id>)/Microsoft.Dynamics.CRM.wa_GetContactSyncStatus

Again this is an action targeting contacts and running the wa_GetContactSyncStatus action, change the values to what you need them to be. Also as a side note this is against a 2016 server anything later will have a different api version for you to use. Consult the developer resources page in your crm instance to figure out what your url for the web api is.

The action will run asynchronously and as long as your javascript request is set to be synchronous as well your request will return when the action is complete.

As another side note if you have your action call another workflow that isn't synchronous it will quite probably return before your asynchronous background workflow does.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download