Inspired by a suggestion from my colleague, I am excited to share this blog with you on Business Process Flows (BPF).
When a form displays a business process flow control in the header, additional controls gets added for each attribute that is been displayed in that BPF.
These controls hold unique names like:header_process_.
So using this control we can write script around these fields.
The Controls displayed in the form header are also accessible and hold unique name like:header_.
Show/Hide field:The setVisible
function is used to either show or hide the field based on its argument (true
for show and false
for hide).
We can show and hide business process flow fields using JavaScript in Microsoft Dynamics 365 CRM using the following code:
// To show the business process flow field
Xrm.Page.getControl("header_process_statecode").setVisible(true);
// To hide the business process flow field
Xrm.Page.getControl("header_process_statecode").setVisible(false);
Make the field Read only:
We can make a business process flow field read-only using JavaScript in Microsoft Dynamics 365 CRM with the following code:
Xrm.Page.getControl("header_process_dummyField").setDisabled(true);
Replace this value with the actual logical name of your field.
The setDisabled
function is used to disable the field, making it read-only.
The argument passed to the function is true
, indicating that the field should be disabled.
Filter a lookup field:
You can filter a lookup field based on the value of another field in a business process flow using JavaScript in Microsoft Dynamics 365 CRM.
Here is an example code that demonstrates how to do this:
//Get the value of the first field
var firstFieldValue = Xrm.Page.getAttribute("first_field").getValue();
//Get the lookup field to be filtered
var lookupField = Xrm.Page.getAttribute("lookup_field");
//Check if the first field has a value
if (firstFieldValue) {
//Create the filter array
var filterArray = [];
//Add the filter condition to the array
filterArray.push(new Xrm.Sdk.FilterExpression("field_to_filter", Xrm.Sdk.ConditionOperator.Equal, firstFieldValue[0].id));
//Set the filter for the lookup field
lookupField.setFilter(filterArray);
}
else {
//Clear the filter for the lookup field
lookupField.setFilter(null);
}
Get/Set Value:
We can get and set the value of a business process flow field using JavaScript in Microsoft Dynamics 365 CRM.
Here is an example code that demonstrates how to do this:
//Get the value of a field
var fieldValue = Xrm.Page.getAttribute("header_process_descriptions").getValue();
//Set the value of a field
Xrm.Page.getAttribute("header_process_descriptions").setValue("new_value");
The getAttribute
function is used to get a reference to the field, and the getValue
and setValue
functions are used to get and set the value of the field, respectively.
The argument passed to the setValue
function is a string, "new_value"
, which represents the new value that you want to set for the field.
Lock and Unlock Field:
We can lock and unlock a business process flow field using JavaScript in Microsoft Dynamics 365 CRM.
//Lock a field
Xrm.Page.getControl("field_logical_name").setDisabled(true);
//Unlock a field
Xrm.Page.getControl("field_logical_name").setDisabled(false);
field_logical_name
is the logical name of the field that you want to lock or unlock. Replace this value with the actual logical name of your field.
The getControl
function is used to get a reference to the field, and the setDisabled
function is used to set the field to be either disabled (locked) or enabled (unlocked).
The argument passed to the setDisabled
function is true
to lock the field, or false
to unlock the field.
I hope you found this information helpful and it answered your questions. If you have any further questions, feel free to ask. Thank you for reading!🙏