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
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
It is possible to make use of the Conditionally Invalid Values bind in a JavaScript business action. This will resolve to a (possibly empty) set of values, and this set will contain all values which has value conditions that for the current node evaluates to false.
Note: Note that 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();
//do some chatting 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
It is possible to make use of the workflow state bindings for conditions and actions that, on the import, can resolve and be used for general evaluation and handling of the product being imported.
This is an example business condition that be applied on import of a maintenance Smartsheet, 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 return 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
}
//now 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: we have a task and will now continue with import');
return true;