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.
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”).unbind(“click”);
$(“#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!
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
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”);
Since you are using 2015, you no longer need to use the unsupported customizations to handle the previous/ next stage movements. There are OOB APIs to handle the same which have been introduced in CRM 2015.
Please check the following link – https://msdn.microsoft.com/en-us/library/dn817874.aspx
Regards
Debajit
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?
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?
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.
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….
Thanks,
Pavan
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?
Pingback: Registering custom client handlers for your business process flow stage handlers –Dynamics CRM | Debajit's Dynamic CRM Blog
Pingback: Debajit's Dynamics CRM Blog
Hi Debajit, can we hide these buttons in Unified Interface?
No longer but you can certainly stop their movement – https://debajmecrm.com/2020/06/01/user-confirmation-on-business-process-flow-stage-change-stop-back-stage-movement-stop-stage-movement-based-on-custom-business-logic-all-this-and-everything-from-client-side-in-dynamics-365-b/