Scripting on Business Process Flow in CRM 2015- Part II

By | March 5, 2015

In our previous first part blog, we explained about BPF, it`s enhancements and few of the methods from the list of available methods. This second blog installation will explain the other available methods.

  • Get the Active Path

We can get the Active Path i.e., serves the exact seq. of stages that got the user to where he is now, the stage he is on and the predicted set of future stages on the basis of Branching rules.

Snippet:

var stgColl = Xrm.Page.data.process.getActivePath()

  • Get the Enabled Processes

We can get the list of enabled processes for a particular entity which user can use to switch.

Snippet:

Xrm.Page.data.process.getEnabledProcess(callbackFunction(enabledProcesses))

callbackFunction(enabledProcesses) :  This callback function will accept a parameter. The parameter will be an object having the list of enabled processes.

  • Navigate Previous or Next

What if you want to move the user next or prev depending on the value of a step on the current stage, to make that happen, we have 2 functions:

  • moveNext:

This will move the user to the next stage.

Snippet:

Xrm.Page.data.process.moveNext(callbackFunction)

callbackFunction: The callback function can be used to perform any actions that needs to be done after moving the user to the next stage.

  • movePrevious:

This will move the user to the previous stage.

Snippet:

Xrm.Page.data.process.movePrevious(callbackFunction)

callbackFunction: The callback function can be used to perform any actions that needs to be done after moving the user to the previous stage.

  • Process Methods

In the first part of the blog, we discussed how to retrieve Active Process. Now, let`s see how to retrieve the properties from the returned object.

var procObj = Xrm.Page.data.process.getActiveProcess();

  • Get the Id:

procObj.getId();

Returns a string.

  • Get the Name:

procObj.getName();

Returns a string.

  • Get the Stage Collection:

procObj.getStages();

Returns the collection of stages

  • Check whether the process is rendered or not:

procObj.isRendered();

Returns a bool.

 

  • Stage Methods

In the first part of the blog, we discussed how to retrieve Active Stage. Now, let`s see how to retrieve the properties from the returned object.

var actStg = Xrm.Page.data.process.getActiveStage();

  • Get the Category:

actStg. getCategory().getValue();

Returns an integer value of the Business Process Flow category.

  • Get the Entity Name:

actStg.getEntityName();

Returns the logical name of the entity.

  • Get the Id:

actStg.getId();

Returns a string.

  • Get the Stage Name:

actStg.getName();

Returns a string.

  • Get the Status:

actStg.getStatus();

Returns “active” or  “inactive”.

  • Get the Steps:

var stpColl = actStg.getSteps();

Returns collection of steps.

  • Step Methods:

In the previous point, we got the step collection. Now, let`s see how to retrieve the properties from the returned object.

  • Get the Logical Name:

stpColl.getAttribute();

Returns the logical name of the step.

  • Get the Name of the step:

stpColl.getName();

Returns the step name.

  • Get the Required Level:

stpColl.isRequired();

Returns a bool.

All these are new addition in the CRM 2015 box and those are the most asked and helpful additions. We can achieve many things by hooking onto stage change and stage select events.

Hope this article helps!