We will learn how to dynamically hide /show and lock / unlock field placed in Business Process Flow with code using the JavaScript. Before we give the JavaScript code snippet let us understand the behavior of the field which is placed in the BPF. When a field in placed in the Stages of the BPF, the data source of the field remains the same as that of the field on the form but the schema name of the field present in PBF gets changed where an extra text “header_process_” is added to the fields actual schema name.
For example, if the field with label “Account Name” and schema name “new_accountname” is placed in the Business Process Flow, then the schema name used to access the field in Business Process Flow via code will be “header_process_new_accountname”.
We will use JavaScript to dynamically hide / show and lock / unlock field based on the certain conditions (Depending upon the value from any other field).
Below is the code where we perform operation on the Business Process Flow field with schema “header_process_BPFFieldSchemaName” depending upon the value in another form field “FormFieldSchemaName”. From the below code use the function “fieldBPF” in the onLoad event of your entity form.
Below is the JavaScript code.
var crmCrateFunction = crmCrateFunction || {}; crmCrateFunction.onLoadFunction = (function (executionContext) {
//Function To Hide / Show / Lock / Unlock Field In Business Process Flow.
var fieldBPF = function (executionContext) { var formContext = executionContext.getFormContext();
//Hide & Lock Field In Business Process Flow Depending Upon Another Field In Form.
if (formContext.getAttribute(“FormFieldSchemaName”).getValue() === “Your Conditional Value”)
{
if (formContext.getControl(“header_process_BPFFieldSchemaName”) !== null && formContext.getControl(“header_process_BPFFieldSchemaName”) !== undefined)
{ formContext.getControl(“header_process_BPFFieldSchemaName”).setDisabled(true); formContext.getControl(“header_process_BPFFieldSchemaName”).setVisible(true); }
}
//Show & Unlock Field In Business Process Flow Depending Upon Another Field In Form.
else {
if (formContext.getControl(“header_process_BPFFieldSchemaName”) !== null && formContext.getControl(“header_process_BPFFieldSchemaName”) !== undefined) { formContext.getControl(“header_process_BPFFieldSchemaName”).setDisabled(false); formContext.getControl(“header_process_BPFFieldSchemaName”).setVisible(false);
}
}
};
}) ();
CRM Crate
All In One Platform For Learning Microsoft CRM.
var crmCrateFunction = crmCrateFunction || {};
crmCrateFunction.onLoadFunction = (function (executionContext) {
//Function To Hide / Show / Lock / Unlock Field In Business Process Flow.
var fieldBPF = function (executionContext) {
var formContext = executionContext.getFormContext();
//Hide & Lock Field In Business Process Flow Depending Upon Another Field In Form.
if (formContext.getAttribute(“FormFieldSchemaName”).getValue() === “Your Conditional Value”) {
if (formContext.getControl(“header_process_BPFFieldSchemaName”) !== null & amp; & amp; formContext.getControl(“header_process_BPFFieldSchemaName”) !== undefined) {
formContext.getControl(“header_process_BPFFieldSchemaName”).setDisabled(true);
formContext.getControl(“header_process_BPFFieldSchemaName”).setVisible(true);
}
}
//Show & Unlock Field In Business Process Flow Depending Upon Another Field In Form.
else {
if (formContext.getControl(“header_process_BPFFieldSchemaName”) !== null & amp; & amp; formContext.getControl(“header_process_BPFFieldSchemaName”) !== undefined) {
formContext.getControl(“header_process_BPFFieldSchemaName”).setDisabled(false);
formContext.getControl(“header_process_BPFFieldSchemaName”).setVisible(false);
}
}
};
})();
Is’nt working when field is added to more than one step in BPF