Business Rules with Conditional Attributes

For information on setting up a conditionally valid attribute, refer to the Conditional Attribute Display documentation in the System Setup here.

For information on adding a bind, refer to the Adding a Bind topic in the Resource Materials online help here.

JavaScript business rule bind for Conditional Validity

The Conditionally Invalid Values bind can be used in a JavaScript business action. This resolves to a (possibly empty) set of values, and the set contains all values which have value conditions that evaluate to 'false' for the current node.

Note: This binding is unrestricted in the sense that it is always available, not just from workflows or imports, etc.

This is a JavaScript example for clearing conditionally invalid values.

Required binds:

  • invalid:"Conditionally Invalid Values"-binding
  • logger:"Logger"-binding
//acquire an iterator - easiest way to deal with Sets
var iter = invalid.iterator();
//iterate over conditionally invalid values
while (iter.hasNext()) {
//get the value
   var val = iter.next();
   //test if there is a value and if it is local
   var clean = val.isLocal() && val.getSimpleValue();
   //write to the log
   var msg
   if (clean) {
      msg = "Cleaning up";
   } else {
      msg = "Ignoring";
   }
   msg += " conditionally invalid ";
   if (val.isLocal()) {
      msg += "local value";
   } else {
      msg += "non-local value";
   }
   msg += val.getAttribute().getID() + " [" + val.getSimpleValue() + "]";
   logger.info( msg );
   //in case of local value - delete it
   if (clean) {
      val.setSimpleValue("");
   }
   //empty string handled as null and deletes local values
}

JavaScript Business Rule Bind of Workflow State

The workflow state bindings can be used for conditions and actions that, upon import, can resolve and be used for general evaluation and handling of the product being imported.

This is an example business condition applied on import of a maintenance Smartsheet and exported from the Web UI Task List.

Required binds:

  • state:"Workflow state"-binding
  • node:"Current Object"-binding
  • logger:"Logger"-binding
//up front test if the import carries expectation of specific workflow state
if (!state) {
   logger.info("No import state provided");
   //could have instead returned some rejection to say no import if a state is not supplied
   return true;
}
var instance, task, msg;
//acquire the workflow instance for the node and workflow
instance = node.getWorkflowInstance(state.getWorkflow());
if (!instance) {
   //reject since workflow has been terminated or never started
   msg = "Rejected: Workflow " + state.getWorkflow().getTitle() + " not started for " + node.getTitle();   
   logger.info(msg);
   return msg
}
//look for actual task for node in supplied state
task = instance.getTask(state);
if (!task){
   //no task also causes rejection
   msg = "Someone might have changed data. " + node.getTitle() + " has no task for state " + state.getID() + " in workflow " + state.getWorkflow().getTitle();
   logger.info(msg);
   return msg;
}
logger.info('Accepted: a task exists, continue with import');
return true;