Make the field on a record page required
Make the Business phone field on the contact page required. The field must be required for the "Customer" type contacts, i. e., the contacts with "Customer" specified in the Type field.
Create a replacing view model schema of the contact page
-
Go to the Configuration section and select a custom package to add the schema.
-
Click Add → Replacing view model on the section list toolbar.
-
Fill out the schema properties.
- Set Code to "ContactPageV2."
- Set Title to "Display schema - Contact card."
- Select "ContactPageV2" in the Parent object property.
-
Add the
BusinessRuleModule
andConfigurationConstants
modules as dependencies to the declaration of the view model class. -
Make the field required.
To do this, set the
rules
property for the Phone column:- Set the
ruleType
property toBINDPARAMETER
. The value sets the business rule type. TheBusinessRuleModule.enums.RuleType
enumeration represents the rule types. - Set the
property
property toREQUIRED
. The value marks the column as required. TheBusinessRuleModule.enums.Property
enumeration represents the properties of theBINDPARAMETER
business rule. - Specify the execution conditions of the business rule in the
conditions
array. The Type column value must match theConfigurationConstants.ContactType.Client
configuration constant that includes the ID of the "Customer" record of the Contact types lookup.
View the source code of the replacement view model of the contact page below.
ContactPageV2/* Specify the BusinessRuleModule and ConfigurationConstants modules as dependencies. */
define("ContactPageV2", ["BusinessRuleModule", "ConfigurationConstants"], function(BusinessRuleModule, ConfigurationConstants) {
return {
/* The name of the record page object's schema. */
entitySchemaName: "Contact",
/* The business rules of the record page's view model. */
rules: {
/* The set of rules for the [Phone] column of the view model. */
"Phone": {
/* The requirement of the [Phone] field depends on the [Type] field value. */
"BindParameterRequiredAccountByType": {
/* The BINDPARAMETER rule type. */
"ruleType": BusinessRuleModule.enums.RuleType.BINDPARAMETER,
/* The rule controls the REQUIRED property. */
"property": BusinessRuleModule.enums.Property.REQUIRED,
/* The array of conditions that trigger the rule. Checks whether the [Type] column value is "Customer." */
"conditions": [{
/* The left side expression of the condition. */
"leftExpression": {
/* The expression type is attribute (column) of the view model. */
"type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
/* The name of the view model column whose value to compare in the expression. */
"attribute": "Type"
},
/* Set the comparison operation type to equal. */
"comparisonType": Terrasoft.ComparisonType.EQUAL,
/* The right side expression of the condition. */
"rightExpression": {
/* Set the expression type to constant. */
"type": BusinessRuleModule.enums.ValueType.CONSTANT,
/* The value to compare to the left side expression. */
"value": ConfigurationConstants.ContactType.Client
}
}]
}
}
}
};
}); - Set the
-
Click Save on the Designer's toolbar.
Outcome of the example
To view the outcome of the example:
- Refresh the Contacts section page.
- Select "Customer" in the Type field of the contact page if needed.
As a result, Creatio will make the Business phone field required for the "Customer" type contacts.
If you try to save a "Customer" type contact whose Business phone field is empty, a message box will open.
The Business phone field is optional for other contact types. For example, "Employee."