<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Business rule to start flow designer in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/business-rule-to-start-flow-designer/m-p/3424414#M5372</link>
    <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I have written a script in business rule to start the flow designer&amp;nbsp;&lt;BR /&gt;condition after - insert &amp;amp; update&lt;BR /&gt;script :-&lt;/P&gt;&lt;P&gt;(function executeRule(current, previous /*null when async*/ ) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var flowSydId = catGR.getValue('flow_designer_flow');&lt;BR /&gt;gs.info("&amp;amp;&amp;amp;0 " + flowSydId);&lt;/P&gt;&lt;P&gt;var inputs = {};&lt;BR /&gt;inputs.requested_item = current;&lt;BR /&gt;inputs.requested_item.sys_id = current.sys_id;&lt;BR /&gt;inputs.table_name = current.getTableName();&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;var runner = sn_fd.FlowAPI.getRunner()&lt;BR /&gt;.flow(flowSydId)&lt;BR /&gt;.inBackground()&lt;BR /&gt;.withInputs(inputs)&lt;BR /&gt;.run();&lt;/P&gt;&lt;P&gt;var contextId = runner &amp;amp;&amp;amp; typeof runner.getContextId === 'function' ? runner.getContextId() : '(not returned)';&lt;/P&gt;&lt;P&gt;gs.info("&amp;amp;&amp;amp;4 Flow triggered for Requested Item: " + current.number +&lt;BR /&gt;" | Flow Sys ID: " + flowSydId +&lt;BR /&gt;" | Context ID: " + contextId);&lt;/P&gt;&lt;P&gt;} catch (e) {&lt;BR /&gt;gs.error("&amp;amp;&amp;amp;5 Error triggering flow: " + e.message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;})(current, previous);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I'm able to retrieve the Flow Designer flow sys_id correctly when the catalog item is changed on a request. The issue arises when switching from an item that uses a &lt;STRONG&gt;Workflow&lt;/STRONG&gt; to one that uses &lt;STRONG&gt;Flow Designer&lt;/STRONG&gt; — in such cases, the RITM gets stuck and doesn't trigger approvals.&lt;/P&gt;&lt;P&gt;To address this, I wrote a script to manually start the Flow Designer flow when the item changes. However, it's not working as expected.&lt;/P&gt;&lt;P&gt;Do you have any suggestions or solutions for handling item changes where the original item runs on Workflow and the new one runs on Flow Designer? Ideally, I want the flow to trigger properly and continue the approval process without getting stuck.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Nov 2025 15:32:41 GMT</pubDate>
    <dc:creator>venkyk1309</dc:creator>
    <dc:date>2025-11-11T15:32:41Z</dc:date>
    <item>
      <title>Business rule to start flow designer</title>
      <link>https://www.servicenow.com/community/community-central-forum/business-rule-to-start-flow-designer/m-p/3424414#M5372</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I have written a script in business rule to start the flow designer&amp;nbsp;&lt;BR /&gt;condition after - insert &amp;amp; update&lt;BR /&gt;script :-&lt;/P&gt;&lt;P&gt;(function executeRule(current, previous /*null when async*/ ) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var flowSydId = catGR.getValue('flow_designer_flow');&lt;BR /&gt;gs.info("&amp;amp;&amp;amp;0 " + flowSydId);&lt;/P&gt;&lt;P&gt;var inputs = {};&lt;BR /&gt;inputs.requested_item = current;&lt;BR /&gt;inputs.requested_item.sys_id = current.sys_id;&lt;BR /&gt;inputs.table_name = current.getTableName();&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;var runner = sn_fd.FlowAPI.getRunner()&lt;BR /&gt;.flow(flowSydId)&lt;BR /&gt;.inBackground()&lt;BR /&gt;.withInputs(inputs)&lt;BR /&gt;.run();&lt;/P&gt;&lt;P&gt;var contextId = runner &amp;amp;&amp;amp; typeof runner.getContextId === 'function' ? runner.getContextId() : '(not returned)';&lt;/P&gt;&lt;P&gt;gs.info("&amp;amp;&amp;amp;4 Flow triggered for Requested Item: " + current.number +&lt;BR /&gt;" | Flow Sys ID: " + flowSydId +&lt;BR /&gt;" | Context ID: " + contextId);&lt;/P&gt;&lt;P&gt;} catch (e) {&lt;BR /&gt;gs.error("&amp;amp;&amp;amp;5 Error triggering flow: " + e.message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;})(current, previous);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I'm able to retrieve the Flow Designer flow sys_id correctly when the catalog item is changed on a request. The issue arises when switching from an item that uses a &lt;STRONG&gt;Workflow&lt;/STRONG&gt; to one that uses &lt;STRONG&gt;Flow Designer&lt;/STRONG&gt; — in such cases, the RITM gets stuck and doesn't trigger approvals.&lt;/P&gt;&lt;P&gt;To address this, I wrote a script to manually start the Flow Designer flow when the item changes. However, it's not working as expected.&lt;/P&gt;&lt;P&gt;Do you have any suggestions or solutions for handling item changes where the original item runs on Workflow and the new one runs on Flow Designer? Ideally, I want the flow to trigger properly and continue the approval process without getting stuck.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 15:32:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/business-rule-to-start-flow-designer/m-p/3424414#M5372</guid>
      <dc:creator>venkyk1309</dc:creator>
      <dc:date>2025-11-11T15:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Business rule to start flow designer</title>
      <link>https://www.servicenow.com/community/community-central-forum/business-rule-to-start-flow-designer/m-p/3424750#M5384</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/848679"&gt;@venkyk1309&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;The fundamental problem is likely that the RITM already has an active or completed workflow context attached from the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;original&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;catalog item. When you change the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;cat_item&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and try to manually start a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Flow Designer&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;flow via a Business Rule, the platform gets confused because the RITM record is still linked to the old execution path.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try updating script like below:&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;Condition:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;current.cat_item.changes()&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;When:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;after&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;update&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;Order&lt;/STRONG&gt;: 1000&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;function&lt;/SPAN&gt;&lt;SPAN class=""&gt; executeRule(current, previous &lt;/SPAN&gt;&lt;SPAN class=""&gt;/*null when async*/&lt;/SPAN&gt;&lt;SPAN class=""&gt; ) {

    &lt;/SPAN&gt;&lt;SPAN class=""&gt;// 1. Define the function to cancel existing workflows&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;function&lt;/SPAN&gt;&lt;SPAN class=""&gt; cancelExistingWorkflow(ritmSysId) {
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; wf = &lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt;&lt;SPAN class=""&gt; Workflow();
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; contextGr = &lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt;&lt;SPAN class=""&gt; GlideRecord(&lt;/SPAN&gt;&lt;SPAN class=""&gt;'wf_context'&lt;/SPAN&gt;&lt;SPAN class=""&gt;);
        contextGr.addQuery(&lt;/SPAN&gt;&lt;SPAN class=""&gt;'id'&lt;/SPAN&gt;&lt;SPAN class=""&gt;, ritmSysId);
        contextGr.addQuery(&lt;/SPAN&gt;&lt;SPAN class=""&gt;'state'&lt;/SPAN&gt;&lt;SPAN class=""&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;'executing'&lt;/SPAN&gt;&lt;SPAN class=""&gt;);
        contextGr.setLimit(&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;);
        contextGr.query();
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt;&lt;SPAN class=""&gt; (contextGr.next()) {
            gs.info(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&amp;amp;&amp;amp;0 Canceling existing workflow context: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + contextGr.sys_id + &lt;/SPAN&gt;&lt;SPAN class=""&gt;" for RITM: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + ritmSysId);
            wf.cancel(contextGr.sys_id);
            &lt;/SPAN&gt;&lt;SPAN class=""&gt;// Give the cancellation a moment to process before starting the new flow&lt;/SPAN&gt;&lt;SPAN class=""&gt;            &lt;BR /&gt;               gs.sleep(&lt;/SPAN&gt;&lt;SPAN class=""&gt;500&lt;/SPAN&gt;&lt;SPAN class=""&gt;); 
        }
    }

    &lt;/SPAN&gt;&lt;SPAN class=""&gt;// 2. Main Logic: Check if the new catalog item uses a Flow Designer flow&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; catGR = &lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt;&lt;SPAN class=""&gt; GlideRecord(&lt;/SPAN&gt;&lt;SPAN class=""&gt;'sc_cat_item'&lt;/SPAN&gt;&lt;SPAN class=""&gt;);
    &lt;/SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt;&lt;SPAN class=""&gt; (!catGR.&lt;/SPAN&gt;&lt;SPAN class=""&gt;get&lt;/SPAN&gt;&lt;SPAN class=""&gt;(current.cat_item)) {
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;return&lt;/SPAN&gt;&lt;SPAN class=""&gt;; &lt;/SPAN&gt;&lt;SPAN class=""&gt;// Exit if the new catalog item can't be found&lt;/SPAN&gt;&lt;SPAN class=""&gt;    &lt;BR /&gt;}

    &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; flowSysId = catGR.getValue(&lt;/SPAN&gt;&lt;SPAN class=""&gt;'flow_designer_flow'&lt;/SPAN&gt;&lt;SPAN class=""&gt;);

    &lt;/SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt;&lt;SPAN class=""&gt; (flowSysId) {
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;// If the new item uses a flow, cancel the old workflow first&lt;/SPAN&gt;&lt;SPAN class=""&gt;        &lt;BR /&gt;cancelExistingWorkflow(current.sys_id);

        &lt;/SPAN&gt;&lt;SPAN class=""&gt;// 3. Start the new Flow Designer flow&lt;/SPAN&gt;
        &lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; inputs = {};
        &lt;/SPAN&gt;&lt;SPAN class=""&gt;// Pass the RITM record correctly as input&lt;/SPAN&gt;&lt;SPAN class=""&gt;        &lt;BR /&gt;              inputs.requested_item = current; 

        &lt;/SPAN&gt;&lt;SPAN class=""&gt;try&lt;/SPAN&gt;&lt;SPAN class=""&gt; {
            &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; runner = sn_fd.FlowAPI.getRunner()
                .flow(flowSysId)
                .inBackground()
                .withInputs(inputs)
                .run();

            &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; contextId = runner &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;typeof&lt;/SPAN&gt;&lt;SPAN class=""&gt; runner.getContextId === &lt;/SPAN&gt;&lt;SPAN class=""&gt;'function'&lt;/SPAN&gt;&lt;SPAN class=""&gt; ? runner.getContextId() : &lt;/SPAN&gt;&lt;SPAN class=""&gt;'(not returned)'&lt;/SPAN&gt;&lt;SPAN class=""&gt;;

            gs.info(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&amp;amp;&amp;amp;4 Flow triggered for Requested Item: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + current.&lt;/SPAN&gt;&lt;SPAN class=""&gt;number&lt;/SPAN&gt;&lt;SPAN class=""&gt; +
                &lt;/SPAN&gt;&lt;SPAN class=""&gt;" | Flow Sys ID: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + flowSysId +
                &lt;/SPAN&gt;&lt;SPAN class=""&gt;" | Context ID: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + contextId);

        } &lt;/SPAN&gt;&lt;SPAN class=""&gt;catch&lt;/SPAN&gt;&lt;SPAN class=""&gt; (e) {
            gs.error(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&amp;amp;&amp;amp;5 Error triggering flow via Business Rule: "&lt;/SPAN&gt;&lt;SPAN class=""&gt; + e.message);
        }
    }

})(current, previous);&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;!--   StartFragment    --&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;Thanks, GP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;!--   EndFragment    --&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2025 05:40:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/business-rule-to-start-flow-designer/m-p/3424750#M5384</guid>
      <dc:creator>G Ponsekar</dc:creator>
      <dc:date>2025-11-12T05:40:07Z</dc:date>
    </item>
  </channel>
</rss>

