While working with BPF fields using JavaScript, there can be instances where you might want to keep the field locked in a certain stage but unlocked in another stage. And using Xrm.Page.getControl(controlName) or for v9 – getFormContext.getControl(controlName) should differentiate between the 2 fields?
Let’s see what we need to do here.
Scenario
- Let’s say I want the users to enter Customer Need data in Develop Stage.
- But, just view what data is present in Propose Stage shown below, not modify it. (I’ve just renamed the field to Summarize Customer Need instead)
JavaScript Usage to access the Control
- Now, since the Summarize Customer Need field is the second time, using getFormContext.getControl(“header_process_customerneed”) will be fetched to disable the first field only i.e. Customer Need in Develop stage.
- To access Summarize Customer Need, you need to append “_1” to the control name for the second occurrence. And _2 and so on for further occurrences.
Here’s the sample code which I used to access Summarize Customer Need to access the second occurrence of the field and use setDisabled(true) to lock it –
3. And that way, you’ll be able to access Summarize Customer Need control and do your desired operation (like even make it hidden or visible depending on your scenario) –
Hope this helps!