This is a requirement I have recently received and the requirement was – “Users should not be able to abandon or finish a business process flow”. You may be thinking this has to be done using plugins. Off-course this can be done using plugins. Off course you can do it. But then you have to throw an InvalidPluginExecutionException from your plugins. And the end-user shall get the message in Business process flow dialog which have been perennially disliked by users.
But is there some other way. Off course there is. And surprisingly many are now aware of it.
Now in Business Process flow API’s of Dynamics 365, we have a special event where we can register our custom function – onPreProcessStatusChange. The event is fired when the user tries to change the status of Business process flow record.
Below is the code to register an event handler for this event. In the code all I am doing is preventing the user from changing the status of Business process flow.
formContext.data.process.addOnPreProcessStatusChange(function (e) {
e.getEventArgs().preventDefault();
var alertStrings = { confirmButtonLabel: “OK”, text: “This operation is not allowed.”, title: “Status Change!” };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions)
});
And below is the experience
Hope this helps! Follow my blog for more interesting articles on Dynamics 365 and PowerApps
Debajit Dutta
(Dynamics MVP)
For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
Our product offerings:
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
Hi Debajit,
I am new for Dynamic 365 and model driven apps.
Can you please guide me where I have to put that code?
Thanks ,
Sanjeev
Thanks Sanjeev for reading my blog. You have to put it in the form load event of the record.
-Debajit