Anyone who would have tried using the api functions available to access the controls on the Business Process Flow to hide/lock in CRM 2013 would know that the function only worked if the control was on the current active stage on the form.
Suppose you had 2 stages Develop and Propose and you had a field added to the Propose stage. This field should be conditionally editable. Back then we could write code on the form load to access the control and lock/hide it. This is available as a blog written earlier explaining this new availability http://www.inogic.com/blog/2014/07/how-to-apply-script-on-header-fields-and-bpf-fields/
However, this code failed to lock/hide the field if when you open the form, the current stage was Develop and not Propose. The reason being the controls on the other stages were not created on the form, only the controls on the current stage of the BPF were available.
This really made this unusable as it is not necessary that the control that we need to hide/lock would be on the active stage always.
How to Fix this?
With CRM 2015, we now have the ability to add hooks to the stage change event. You can attach a function to the OnStageChange event that is executed whenever you move to the Previous/Next stage in the BPF. The OnStageChange event would only execute when the stage is changed, we noticed that now if you write the code to access the controls on BPF of a stage that is not the active one, it does find the control and lock/hide it as desired. This ensures that even simply switching between the process tabs, ensure that the field is locked and there is no way to edit the control on the BPF.
Here is how we do it:
Note we are attaching the event handle to the StageChange event of the BPF
The fields in the BPF should be accessed as header_process_<attribute name>.
After you have this code published, you will find that fields locked through the above code, it non-editable irrespective of the active BPF stage you are in and the controls that need to be locked are in.
Need more from your Dynamics CRM? Avoid double entry data work. Check our Inolink to promote orders/invoices from QuickBooks to Dynamics CRM. Email us on email@example.com for a trial or if you would like to see a live demo.