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!

Advertisements

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 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

2 thoughts on “Registering custom client handlers for your business process flow stage handlers –Dynamics CRM”

    1. Hi

      This API was designed for CRM 2013 when there was no client side script to handle business process flow changes OOB. It’s based on the document object rendering.

      In 2016 the form rendering engine works differently from CRM 2013 and hence the document object might not be available at the time the script is executing,

      Also in 2016, you need to use this at all since you have very powerful OOB Xrm scripts to handle business process events.

      But still I would like to know if there is any specific scenario where you need it and OOB stuff is not working for your requirement.

      Regards
      Debajit

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