{Dynamics CRM} Control CRM 2013 Business Process Next Stage and Previous Stage flow using JScript.

Recently in our project we needed to restrict the business process flow from one stage to another depending on certain conditions. The problem was that OOB CRM 2013 does allow you to plugin your custom client side code when the “Next Stage” or the “Previous Stage” icons are clicked. You can obviously register Plugins and Workflows on the business process stage change but you cannot stop the change of stages using the same. Let’s see how we can achieve this.

Below is the screenshot of an example business process flow for opportunity entity. Let’s explore what CRM does here. I have opened Chrome Developer tools and trying to explore the HTML for business process flow. I have selected the ‘Next Stage’ button.

screen 9

The id of the div is “stageAdvanceActionContainer”.

So what we need to do is override the click event with our custom function and then if our condition meets we would call the OOB event handler. The code below does the same.

function  registerBusinessProcessEvents()


var originalNextStageHandler = $(“#stageAdvanceActionContainer”).data(“events”)[“click”][0].handler;


// unbind the original next event handler



$(“#stageAdvanceActionContainer”).click(function (e) {

// perform your custom logic here. If you want to move to the next stage just call the code below.


$.proxy(originalNextStageHandler, $(“#stageAdvanceActionContainer”))(e);





All you need to do is call the registerBusinessProcessEvents  function during the onload of the form.

Similarly the ID for the previous click handler is “stageBackActionContainer”. And you can handle it in the same manner as above.


Please note that is an unsupported customization and might not work if Microsoft decides to change the id of the div elements or the rendering model in future rollups.


Hope this helps!

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

9 thoughts on “{Dynamics CRM} Control CRM 2013 Business Process Next Stage and Previous Stage flow using JScript.”

  1. I am unable to capture the default handler in MS CRM 2015 (below is the code), will there be any other approach?

    var originalNextStageHandler = $._data($(“#stageAdvanceActionContainer”)[0], “events”);

      1. You are right there are supported customizations to handle process stage events. But OnStageChange event will fire after the stage change but I need to handle few validation before the stage change. Is there any way to handle this using OOB?

  2. Hi,

    I want to prevent opening a form on double clicking the record in a subgrid in ms crm 2011, can you please tell how to achieve this?
    How to interact with the oob event handler..any idea?

    1. Hi Pavan,
      Thanks for reading my post.
      Would like to know here the requirement like why you want to block the the double click of the row of the subgrid? Perhaps we can have an alternative solution here.

      1. Hi Debajit,

        Sorry for my late response.I want users not to open the activity record in activity subgrid in a custom entity,which is of particular subject. But all users must be able to see all the records in all views…
        Only the owner can open the activity record and rest are restricted ….so i am checking for preventing form onload(oob)…Can you think on this tell me any other possible solution….


      2. Hi Pavan,
        Since all users can see the activities the in the views, is there any harm if they can still open the activity and see it but only in read-only mode so that they cannot modify it?

Leave a Reply to Debajit Cancel 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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s