官术网_书友最值得收藏!

  • Learning ServiceNow
  • Tim Woodruff
  • 235字
  • 2021-07-09 18:48:24

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

主站蜘蛛池模板: 萍乡市| 大连市| 苍山县| 贡觉县| 桑日县| 岳西县| 开原市| 安新县| 赤水市| 宜阳县| 博客| 连州市| 钟祥市| 偃师市| 宝坻区| 孟津县| 札达县| 兴国县| 报价| 绥阳县| 清新县| 安龙县| 四子王旗| 和平县| 襄垣县| 界首市| 衡南县| 田东县| 镇原县| 藁城市| 咸阳市| 许昌县| 宝应县| 靖宇县| 南通市| 仁化县| 宜城市| 东至县| 阜平县| 喀什市| 定日县|