Have you ever tried implementing a JavaScript on an entity form and wonder why it didn’t take effect in the header or BPF fields? Technically, the field in the form should be the same with the header or BPF fields, right? That’s true but not in scripting perspective.

By default, Dynamics CRM sees these fields differently in terms of scripts. In this blog, I will show how to reference the header and bpf fields and apply the scripts as well.

Solution

Let’s say we have our Contact form and we have fields ‘VIP?’ and ‘VIP Card Number’.  As a simple example, we want to and lock the VIP Card Number (displayed in form and header) IF VIP = False.

apply-javascript-to-header-and-bpf-fields

 

The key point here is to know that the controls displayed in the header holds a unique name and in order to reference it, you must add the prefix “header_” to the name of the field. Please note this goes similar with BPF fields, but you should use “header_process_”.

Here is the code snippet of the said script.

code-snippet-to-apply-header-and-bpf-fields

 

apply javascript to header and bpf fields 2

 

Attaching a script in the header or BPF fields may come in handy depending on our requirement. You could do and apply a lot of basic scripting like hide/show of fields, filter lookup, get/set value etc. But please also note that we cannot add event handlers on the BPF fields itself. In order to do this, we can add the field to the form and there you can attach the event.