This post is in continuation to the my previous post – https://debajmecrm.com/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!
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
Tried it with CRM 2016 and it does not seem to work.
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