Set up the display condition of a field on a page
Set up the display condition for the Sick leave, days left field on the record page of the custom Requests section. Display the field for requests that originate from employees, i. e., requests whose Originator type field is set to "Employee."
1. Set up the page UI
-
Create a custom
Requests
app based on the Records & business processes template. To do this, follow the guide in the user documentation: Create a custom app. -
Open the Requests form page page in the working area of the
Requests
app page.The Requests form page page includes the Name field by default.
-
Add a field that contains the request originator type.
-
Add a Dropdown type field to the working area of the Freedom UI Designer.
-
Click in the action panel of the Freedom UI Designer and fill out the field properties in the setup area.
- Set Title to "Originator type."
- Set Code to "UsrOriginatorType."
- Select "Contact type" in the Lookup property.
-
-
Add a field that contains the number of sick days left.
-
Add a Number type field to the working area of the Freedom UI Designer.
-
Click in the action panel of the Freedom UI Designer and fill out the field properties in the setup area.
- Set Title to "Sick leave, days left."
- Set Code to "UsrSickDaysLeft."
-
-
Click in the action panel of the Freedom UI Designer. After you save the page settings, Creatio opens the source code of the Freedom UI page.
2. Set up the field display condition
Configure the business logic in the Client Module Designer. For this example, set up the field display condition.
-
Add an
IsRequestFromEmployee
attribute that stores data about the contact type from which the request originates to theviewModelConfigDiff
schema section.viewModelConfigDiff schema sectionviewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG*/{
"attributes": {
...,
/* The attribute that stores the request originator type. */
"IsRequestFromEmployee": {}
}
}/**SCHEMA_VIEW_MODEL_CONFIG*/, -
Bind the
visible
property of theUsrSickDaysLeft
element to theIsRequestFromEmployee
model attribute in theviewConfigDiff
schema section. If the request originates from an Employee type contact, display the Sick leave, days left field. Hide the field for other contact types.viewConfigDiff schema sectionviewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
...,
{
"operation": "insert",
"name": "UsrSickDaysLeft",
"values": {
...,
/* The property that flags the field as visible. Bound to the IsRequestFromEmployee attribute. */
"visible": "$IsRequestFromEmployee"
},
...
}
]/**SCHEMA_VIEW_CONFIG_DIFF*/, -
Add a custom implementation of the
crt.HandleViewModelAttributeChangeRequest
system query handler to thehandlers
schema section. Run the handler when the value of any attribute changes, including changes made after loading the attribute values from the data source. The handler checks theUsrOriginatorType
attribute value. If the new attribute value refers to the "Employee" value of the Contact type lookup, set theIsRequestFromEmployee
attribute value totrue
, otherwise set it tofalse
. The unique ID of the Employee type contact set as theemployeeOriginatorTypeId
constant is stored in the corresponding string of the Contact type lookup record. In this example, the ID of the Employee type contact is "60733efc-f36b-1410-a883-16d83cab0980."handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelAttributeChangeRequest",
/* The custom implementation of the system query handler. */
handler: async (request, next) => {
/* Check the request originator type. */
if (request.attributeName === 'UsrOriginatorType') {
const employeeOriginatorTypeId = '60733efc-f36b-1410-a883-16d83cab0980';
const selectedOriginatorType = await request.$context.UsrOriginatorType;
const selectedOriginatorTypeId = selectedOriginatorType?.value;
/* If the request originates from an employee, set the IsRequestFromEmployee to true. */
request.$context.IsRequestFromEmployee = selectedOriginatorTypeId === employeeOriginatorTypeId;
}
/* Call the next handler (if it exists) and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/, -
Click Save on the Client Module Designer's toolbar.
Outcome of the example
To view the outcome of the example:
- Open the
Requests
app page and click Run app. - Click New on the
Requests
app toolbar. - Enter "Sick leave" in the Name field.
- Select "Employee" in the Originator type field.
As a result, Creatio will display the Sick leave, days left field on the page of the request that originates from an Employee type contact.
Creatio will not display the Sick leave, days left field for requests that originate from other contact types, e. g., Customer.
Source codes
/* AMD module declaration. */
define("UsrAppRequests_FormPage", /**SCHEMA_DEPS*/[]/**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/()/**SCHEMA_ARGS*/ {
return {
viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
{
"operation": "insert",
"name": "UsrName",
"values": {
"layoutConfig": {
"column": 1,
"row": 1,
"colSpan": 1,
"rowSpan": 1
},
"type": "crt.Input",
"label": "$Resources.Strings.UsrName",
"control": "$UsrName"
},
"parentName": "LeftAreaProfileContainer",
"propertyName": "items",
"index": 0
},
{
"operation": "insert",
"name": "UsrOriginatorType",
"values": {
"layoutConfig": {
"column": 1,
"row": 2,
"colSpan": 1,
"rowSpan": 1
},
"type": "crt.ComboBox",
"loading": false,
"control": "$UsrOriginatorType",
"label": "$Resources.Strings.UsrOriginatorType",
"items": "$UsrOriginatorType_List",
"attributeName": "UsrOriginatorType",
"isAddAllowed": true,
"showValueAsLink": true
},
"parentName": "LeftAreaProfileContainer",
"propertyName": "items",
"index": 1
},
{
"operation": "insert",
"name": "UsrSickDaysLeft",
"values": {
"layoutConfig": {
"column": 1,
"row": 3,
"colSpan": 1,
"rowSpan": 1
},
"type": "crt.NumberInput",
"control": "$UsrSickDaysLeft",
"label": "$Resources.Strings.UsrSickDaysLeft",
/* The property that flags the field as visible. Bound to the IsRequestFromEmployee attribute. */
"visible": "$IsRequestFromEmployee"
},
"parentName": "LeftAreaProfileContainer",
"propertyName": "items",
"index": 2
}
]/**SCHEMA_VIEW_CONFIG_DIFF*/,
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG*/{
"attributes": {
"UsrName": {
"modelConfigDiff": {
"path": "PDS.UsrName"
}
},
"Id": {
"modelConfigDiff": {
"path": "PDS.Id"
}
},
"UsrOriginatorType": {
"modelConfigDiff": {
"path": "PDS.UsrOriginatorType"
}
},
"UsrOriginatorType_List": {
"isCollection": true,
"viewModelConfigDiff": {
"attributes": {
"value": {
"modelConfigDiff": {
"path": "UsrOriginatorType_List_DS.Id"
}
},
"displayValue": {
"modelConfigDiff": {
"path": "UsrOriginatorType_List_DS.Name"
}
}
}
},
"modelConfigDiff": {
"path": "UsrOriginatorType_List_DS",
"sortingConfig": {
"attributeName": "UsrOriginatorType_List_Sorting",
"default": [
{
"columnName": "Name",
"direction": "asc"
}
]
},
"pagingConfig": {
"rowCount": 50,
"rowsOffset": null
}
},
"embeddedModel": {
"name": "UsrOriginatorType_List_DS",
"config": {
"type": "crt.EntityDataSource",
"config": {
"entitySchemaName": "ContactType"
}
}
}
},
"UsrOriginatorType_List_Sorting": {
"isCollection": true,
"viewModelConfigDiff": {
"attributes": {
"columnName": {},
"direction": {}
}
}
},
"UsrSickDaysLeft": {
"modelConfigDiff": {
"path": "PDS.UsrSickDaysLeft"
}
},
/* The attribute that stores the request originator type. */
"IsRequestFromEmployee": {}
}
}/**SCHEMA_VIEW_MODEL_CONFIG*/,
modelConfigDiff: /**SCHEMA_MODEL_CONFIG*/{
"dataSources": {
"PDS": {
"type": "crt.EntityDataSource",
"config": {
"entitySchemaName": "UsrAppRequests"
}
}
}
}/**SCHEMA_MODEL_CONFIG*/,
handlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelAttributeChangeRequest",
/* The custom implementation of the system query handler. */
handler: async (request, next) => {
/* Check the request originator type. */
if (request.attributeName === 'UsrOriginatorType') {
const employeeOriginatorTypeId = '60733efc-f36b-1410-a883-16d83cab0980';
const selectedOriginatorType = await request.$context.UsrOriginatorType;
const selectedOriginatorTypeId = selectedOriginatorType?.value;
/* If the request originates from an employee, set the IsRequestFromEmployee to true. */
request.$context.IsRequestFromEmployee = selectedOriginatorTypeId === employeeOriginatorTypeId;
}
/* Call the next handler (if it exists) and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/,
converters: /**SCHEMA_CONVERTERS*/{}/**SCHEMA_CONVERTERS*/,
validators: /**SCHEMA_VALIDATORS*/{}/**SCHEMA_VALIDATORS*/
};
});