diff --git a/Server-Side Components/Business Rules/Start a Flow/README.md b/Server-Side Components/Business Rules/Start a Flow/README.md new file mode 100644 index 0000000000..c0d1050023 --- /dev/null +++ b/Server-Side Components/Business Rules/Start a Flow/README.md @@ -0,0 +1,2 @@ +Start a flow asynchronously from Workflow Studio using a business rule. + sn_fd.FlowAPI.getRunner().flow('global.flowName').inBackground().withInputs(inputs).run(); diff --git a/Server-Side Components/Business Rules/Start a Flow/script.js b/Server-Side Components/Business Rules/Start a Flow/script.js new file mode 100644 index 0000000000..40d18e73f0 --- /dev/null +++ b/Server-Side Components/Business Rules/Start a Flow/script.js @@ -0,0 +1,19 @@ +//Table: Change Task +// When: After Delete +// When any of the associated change tasks are deleted, calling the flow asynchronously to make the updates. +(function executeRule(current, previous /*null when async*/ ) { + try { + var chgTask = new GlideRecord('change_task'); + chgTask.addQuery('change_request', current.change_request); + chgTask.query(); + if (chgTask.next()) { + var inputs = {}; + inputs['current'] = chgTask; + inputs['table_name'] = 'change_task'; + sn_fd.FlowAPI.getRunner().flow('global.calculateActualStartEndDates').inBackground().withInputs(inputs).run(); + } + } catch (ex) { + var message = ex.getMessage(); + gs.error(message); + } +})(current, previous);