The attribute validation calculation profile determines whether an attribute has a legal value.

Profile variables

Variable nameTypeDescription
$mapFeatureSetCollectionThe list of layers in the web map. Can be used with the FeatureSetByName or FeatureSetById function to get a particular layer in the map. This can then be queried.
$userIdTextThe unique user ID of the editor who is logged into the application.
$userNameTextThe full name of the editor who is logged into the application.
$userIdentityTextProvides a credential instance. This can be used when accessing external layers with the FeatureLayer function. The credentials represent the user’s logged in credentials.
$sessionDictionaryA dictionary containing key value pairs. The dictionary contains all the session variables that have been configured in the app. When the application first launches, the user will be asked for values for the session variables. They can also (if configured) change session variables in the application. This provides programmatic access to the user’s choices / settings.
$editingLayerFeatureSetThe layer to which $feature belongs to. Can be queried to find other records.
$feature
Feature
The feature that has been edited, added or worked on.
$valueAnyThe value to test in the script. Certain rules, such as the restrict domain values rule, pass in a value for the current field value.
$parentFeature
Feature
If there is a geographic contains relationship for the current feature being edited, this variable will contain the parent (or containing feature).
$routeFeature
Feature
If the feature is a linear referencing feature, this variable will reference source route/line feature.
$onlyCausedByCrackingBooleanBoolean value to indicate that this feature has only been changed to add vertices to prevent slithers appearing.

Return types

Boolean | Text

ValueDescription
trueThe feature is valid.
falseThe feature is not valid.
‘reason’Customized reason why the attribute is not valid.

Example

Validates value is between two numbers:

/**Validate that a field attribute value is between 10 and 20
 *
 * This script validates that value sits within a specific range.
 *
 * The DefaultValue() function is used to ensure that if the field is blank,
 * then the script will not error due to trying to compare an empty value
 * within the condition.
 *
 * The script returns true for valid, false for invalid.
 *
 */

// get the current field value, if blank assign to be -1.
var f = DefaultValue($value, -1);

//check that the value lies in the numeric range of 10 to 20
if (f > 10 && f < 20) {
  return true; // valid
} else {
  return false; // invalid
}