Mandatory Bind
The Data Validation 'Mandatory' bind allows running a JavaScript-based business condition that sets selected attributes and references as mandatory in the Web UI. A message can also be displayed in the Web UI to give the user more information about why the object is mandatory.
All 'Mandatory' methods are available in the STEP API documentation accessible at [system]/sdk or from the system Start Page.
Important: Careful testing is recommended when using the Mandatory Bind.
-
When a mandatory parameter becomes hidden or read-only, the user may not be allowed or even recognize that a mandatory value is missing.
For general information about the Data Validation binds, refer to the Data Validation Binds topic here.
For information about mandatory binds used in workflows, refer to the Mandatory Attributes and References in Workflows topic in the Workflows documentation here.
For objects with both the Mandatory and Read Only binds, the Mandatory message is displayed and the Read Only message follows.
This bind is found within the 'Binds to' dropdown, as shown below.
Configuration
To use any bind:
-
Create a business rule as defined in the Creating a Business Rule, Function, or Library topic here.
-
Edit the business rule as defined in the Editing a Business Rule or Function topic here.
-
In the Edit Operation dialog, add the bind to a business rule, as defined in the Adding a Bind topic in the Reference Materials documentation here.
-
In the Edit Operation dialog, optionally add Messages, as defined in the Adding a Localized Business Rule Message topic here.
-
In the Edit Operation dialog, add JavaScript to call the bind.
Examples
The following JavaScript examples use the related bind(s).
Important: Example scripts should not be used as-is without thorough testing, including updating the script to match object and link types that exist on your system. JavaScript variable names are case-sensitive.
When a mandatory bind is included in a JavaScript business condition, depending on the configuration, either a red asterisk displays for the object or the field with missing data is highlighted in the Web UI. If a custom message is included for the bind, the message is displayed only when no value exists for the mandatory object. If no custom message is provided, the standard message is displayed.
Mandatory attribute based on a value
As an example, a Node Details screen is set up with a number of business conditions that apply validation to a series of attributes configured on that screen. One of those business conditions is configured to ensure that if the value of the attribute 'PrintType' is 'In-Ear,' then the attribute 'SoundInput' is set as Mandatory. If you click into the Mandatory field and click out without entering a value, you receive an error message and cannot save and continue until you have filled in the field.
var attrHome = manager.getAttributeHome();
// Mandatory
if (printType == "In-Ear"){
//mandatory with standard message
mandatory.setMandatory(currentObject, attrHome.getAttributeByID("SoundInput"));
//mandatory with custom message
//mandatory.setMandatory("Sound Input is required for In-Ear types", currentObject, attrHome.getAttributeByID("SoundInput"));
}
return (true);
Note: To update validated attributes dynamically in the Web UI, business conditions applied via the legacy options for the Per Screen - Validation or the Main - Advanced must include an Attribute Value bind for each attribute that should be validated via the business condition. This bind is not required for Web UI validation using the preferred Global Representation List option since the Triggering Data Types parameter provides validation as values are changed. For details, refer to the Configuring Business Conditions in Web UI topic here.
In the example above, the method 'setMandatory' sets the 'SoundInput' attribute as Mandatory and prevents the user from leaving it empty. In this example, the standard message 'Sound Input is mandatory' is displayed on a Node Editor in a Web UI.
Add a custom message by including the message text ('Sound Input is required for In-Ear types') as the first element within the setMandatory method. The custom message is shown commented out on line 7 in the example JavaScript above.
In the Web UI Node Editor image below, the custom message is displayed:
Mandatory validation inside the Globally Configured Unfolding Data Container
The Mandatory bind facilitates the execution of a JavaScript-based business condition for attributes and globally configured references inside the Globally Configured Unfolding data container. This enables users to mark selected attributes and globally configured references as mandatory within the data container.
When the Mandatory bind is included in a JavaScript business condition for the Globally Configured Unfolding Data Container, a red asterisk displays either on the individual attributes or references, or on the collapsed data container. If you click into the field and click out without entering a value, the mandatory field is highlighted, and you will receive an error message. If a custom message is included for the bind, the message is displayed when no value exists for the mandatory object. If no custom message is provided, the standard message is displayed.
The Mandatory bind can be made valid for specified attributes and globally configured references within a specific data container type or data container instance.
// Get the Data Container Type
var dcTypeHome = manager.getHome(com.stibo.core.domain.datacontainertype.DataContainerTypeHome);
var addressDCtype = dcTypeHome.getDataContainerTypeByID("MainAddressDataContainer");
// Set Data Container Type to Mandatory
mandatory.setMandatory("Main Address must be supplied", currObj, addressDCtype);
return true;
In this example, the asterisk indicates that ‘Sold to’ is a mandatory reference within the data container.
If you click into the mandatory field and attempt to remove the reference, the field is highlighted and you will receive a warning message.