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 Technical 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 topic Data Validation Binds.

For information about mandatory binds used in workflows, refer to the topic Mandatory Attributes and References in Workflows in the Workflows documentation.

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:

  1. Create a business rule as defined in the Creating a Business Rule, Function, or Library topic.

  2. Edit the business rule as defined in the Editing a Business Rule or Function topic.

  3. In the Edit Operation dialog, add the bind to a business rule, as defined in the Adding a Bind topic in the Resource Materials online help documentation.

  4. In the Edit Operation dialog, optionally add Messages, as defined in the Localized Messages for JavaScript Business Rules topic.

  5. 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.

Copy
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 topic Configuring Business Conditions in Web UI.

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 data containers

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 and the Globally Configured Multi Edit Data Container. This enables users to mark selected attributes and globally configured references as mandatory within the data containers.

In the Globally Configured Unfolding Data Container, when the Mandatory bind is included in a JavaScript business condition, 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.

Copy
// 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.

In the Globally Configured Multi Edit Data Container, the red asterisk indicating mandatory fields can appear on either a table column or a specific cell.

In this scenario, if the attribute ’Ship to’ is selected, values are required for the ’Bill to’ and ’Sold to’ references.

The mandatory fields are marked with an asterisk within the table.

If the values are removed, a warning message will be displayed, and the corresponding field will be highlighted in orange.

This example shows how the script sets a ‘SAP Sold-to’ reference as mandatory for each instance of the data container object type ‘SAPCustomerSalesAreaData’.

Copy
var attrHome = manager.getAttributeHome();
var dcTypeHome = manager.getHome(com.stibo.core.domain.datacontainertype.DataContainerTypeHome);
var salsAreaDCInstances = currentObj.getDataContainerByTypeID("SAPCustomerSalesAreaData");
var salsAreaArray = salsAreaDCInstances.getDataContainers();
var soldToRefType = manager.getReferenceTypeHome().getReferenceTypeByID("SAP Sold-to");

salsAreaArray.forEach(o =>  {
var dcInstance = o.getDataContainerObject();
mandatory.setMandatory(dcInstance, soldToRefType);
});

return true;