Recently I have been doing quite a bit of work for a customer that involved business process flows, I hit a problem that making a field read only did not affect it in my business proves flow. I also observed a similar behaviour with the header.
Luckily this problem is solvable, in this post I will document the solution.
In my situation I started with a business process flow to make a field read only. I found that it didn’t impact the business process flow. I then found that my normal way of disabling fields from JavaScript also didn’t effect the header fields.
Header Fields
Say we have “Priority” in the header on a case and on the main form. If we wanted to make the priority field read only the following line of JavaScript would normally do the job.
Xrm.Page.getControl("prioritycode").setDisabled(true);
Or to hide we’d use;
Xrm.Page.getControl("prioritycode").setVisible(false);
Neither of these commands will effect the field in the header. To do this we can use an additional control that gets created by prefixing the field name with “header_”. So to make the priority field read only in my header I would use this command;
Xrm.Page.getControl("header_prioritycode").setDisabled(true);
Notice below that my priority field is read only in the header and enabled in the main body of the form. If you wish to effect both two commands would be needed.
Xrm.Page.getControl("header_prioritycode").setDisabled(true);
Xrm.Page.getControl("prioritycode").setDisabled(true);
Business Process Flows
The business process flow shown in the header of the form behaves in a similar manner. Commands to disable fields, make them visible (etc) need to prefix the field name with “header_process_”
Xrm.Page.getControl("header_process_prioritycode").setDisabled(true);
Again notice that this command only impacts the business process flow. If I had the same field existed in the body of the form, header and business process flow three commands would be needed to disable it in all circumstances.
In some circumstances you may have multiple business process flows available, so you’d possibly need to check that a particular field is included before trying to disable it. The syntax for that code would look like this;
var priorityControl = Xrm.Page.getControl("header_process_prioritycode");
if(priorityControl != null) {
priorityControl.setDisabled(true);
}
You can perform other operations on fields in the header such as “getValue”, “getText” or “setValue”. But you cannot use the “Xrm.Page.getAttribute” style syntax as that will give an error. You can however use the approach shown below.
// var priority = Xrm.Page.getAttribute("header_process_prioritycode").getText(); **** Don't use this it gives an error!
var priority = Xrm.Page.getControl("header_process_prioritycode").getAttribute().getText(); // *** Use this instead
alert(priority);
I hope this post is useful if you need to work with fields in the business process flow and header area of CRM forms.
J
Thanks Neil – that’s been driving me nuts for ages…
LikeLike
Thanks Neil. I have come across this recently but its great to see it actually explained so clearly.
LikeLike
I will call my self lucky. Today I got this requirement and here is the solution! Thanks Neil.
LikeLiked by 1 person