Registering custom client handlers for your business process flow stage handlers –Dynamics CRM

This post is in continuation to the my previous post – https://debajmecrm.com/2014/04/18/control-crm-2013-business-process-next-stage-and-previous-stage-flow-using-jscript/

In the above post I have showed how you can override the OOB next and the previous stage clicks and make your own functions to fire when the next or previous stage movements happen. Please note that whatever I have mentioned in the above post is totally unsupported customization and should not be done unless you do not have any other option to try to.

This comes in handy specially in case of Dynamics CRM 2013 where you do not have stage change event handlers on the client side and you have some complex business logic to validate if the stage movement is logical.

Also for CRM 2015, the addOnStageChange is great addition to the library. But these events fire after the stage has been changed. In case you want to fire something before the stage changes from the client side, you might need to use the trick mentioned in the above link.

However many of my blog readers have reported that the above code is not working for them. After my research I could find that to fetch the OOB event handlers for the next and the previous stage clicks, the above link uses the code below.

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

However the data API of jQuery has been deprecated from jQuery 1.8 and above.

If you do not reference the jQuery, CRM by default uses the version 1.7.2 of jQuery. You can find the version of jQuery your page is using by opening developers tools of your browser and typing the below code in the console.

jQuery.fn.jquery

However many a times we refer the advanced versions of jquery in our forms and why not. In that case if your form is referencing jquery version 1.8 or later, then the above code would not work.

In that case you would require to change the code to fetch the event handler to the one below

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

The above code makes use of the private data API in jQuery.

Again a word of caution – It’s an unsupported customization and should not be attempted unless you have no other option.

Hope this helps!