web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

ACCESS BPF AND HEADER FIELDS FROM JAVA SCRIPT

chakkay Profile Picture chakkay 594

While most of you might wonder what’s such a big deal in accessing fields in either business process flow or header of the form. Well the traditional way of accessing BPF fields is to append “header_process” to schema name and appending “header_” to fields on header of the form.

 

However, according to many MVP and system architects, there is high probability of this commands getting deprecated in near future and it would be an inaccurate coding style if we access these fields in aforementioned method. Why do you want to incorporate bugs in code instead work towards flawless code which doesn’t even break in future?

 

Dynamics CRM v9.0 and above recently made a new client API available for developer through which we can get the controls of whole form as a collection. This includes controls of all attributes on form, BPF and header fields.

If you want to lock a field on BPF ‘new_salesreview’, write below command on load CRM event:

Var collection = formContext.data.entity.attributes; (or Xrm.Page)
Collection.forEach(salesReview); //where salesReview is a function

This would return all controls as a collection. Now iterating through for each loop to get required control:

Function salesReview (attribute,index) {
If(attribute.getName() == “new_salesreview”) {
Var control = attribute._controls; //this contains collection of controls if same field is present on form, BPF & header
Control.forEach(disableField); //disableField is a function which loops through each and every collection item
}
}

Function disableField (controlObject, index) {
controlObject.setDisabled(true); //this would lock the same field on form, BPF and header
}

This is one optimal way of getting control of fields in BPF or header and performing actions like show/hide, lock/unlock, set required or not etc. While ‘header_process’ is still supported, I wouldn’t recommend hard coding this in JS because it might break in future releases of CRM.

Comments

*This post is locked for comments