If

The If workflow activity does not so much perform an activity on its own, as it does control the flow of other activities in the workflow based on a condition.

A condition can be defined based on the condition builder (as seen above), or if we check the Advanced tick-box, we can write a script to determine if the If activity should return true or false. After clicking the Advanced tick-box, the Script field will be displayed. This field is auto-populated with a code-comment that provides a fairly detailed explanation as to how to use it:

Answer is a pre-defined variable in the context of this advanced condition script. This variable is a string, not a Boolean; it should be set to the string Yes or No.

After the script runs, whatever the answer variable is set to will determine whether the Yes or No exit conditions are activated:

You could use this script field, for example, to look up related or child records, and divert the workflow along another path depending on whether any related records were, for example, cancelled.

answer = 'no'; 
var gr = new GlideRecord('table_name');
gr.addQuery('state', '7');
gr.addQuery('parent', current.getValue('sys_id'));
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
answer = 'yes';
}
Don't worry if the above code doesn't make much sense to you just yet, we're going to learn all about the GlideRecord class and the Glide API later in this book.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.137.240