<h2>FlowAPI - getRunner()</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="concept" /><meta name="DC.title" content="FlowAPI - Scoped, Global" /><meta name="abstract" content="The FlowAPI provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods." /><meta name="description" content="The FlowAPI provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods." /><meta name="DC.subject" content="FlowAPI, GlideElement, Scoped GlideElement, , FlowAPI, executeActionQuick(String name, Map inputs, Number timeout), executeFlowQuick(String name, Map inputs, Number timeout), startActionQuick(String name, Map inputs), startFlowQuick(String name, Map inputs), i, startSubflowQuick(String name, Map inputs)" /><meta name="keywords" content="FlowAPI, GlideElement, Scoped GlideElement, , FlowAPI, executeActionQuick(String name, Map inputs, Number timeout), executeFlowQuick(String name, Map inputs, Number timeout), startActionQuick(String name, Map inputs), startFlowQuick(String name, Map inputs), i, startSubflowQuick(String name, Map inputs)" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-server.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-implementation-reference.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-reference.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2024-08-01" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="ScriptableFlowAPI" /><link rel="stylesheet" type="text/css" href="../../../../../CSS/commonltr.css" /><title>FlowAPI - Scoped, Global</title></head><body class="api-class"> <div class="nested0" id="ScriptableFlowAPI"> <h1 class="title topictitle1" id="ariaid-title1">FlowAPI - Scoped, Global</h1> <div class="body conbody"><p class="shortdesc">The <span class="keyword apiname">FlowAPI</span> provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods.</p> <p class="p">Access <span class="keyword apiname">FlowAPI</span> methods in global and scoped scripts using the <code class="ph codeph">sn_fd</code> namespace. Create calls to your flows using the <span class="ph uicontrol">Code Snippet</span> action in <span class="ph">Workflow Studio</span> or use the methods detailed here to update scripts manually.</p> <div class="p"><div class="note"><span class="notetitle">Note:</span> <span class="ph">In domain separated instances, flows, subflows, and actions triggered by this API run in the domain of the user who started the script. For example, if a user in the Acme domain starts a script that triggers a flow, the flow runs in the Acme domain and can only access Acme data, even if the flow runs as the System User. </span></div> </div> <div class="p"><div class="note"><span class="notetitle">Note:</span> To optimize instance performance, avoid calling these methods from an asynchronous business rule script. Instead, create a scheduled job record within the <span class="ph">Workflow Studio</span> UI.</div> </div> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../../../build/applications/concept/api-server.html" title="Use server APIs in scripts to change the functionality of applications, or when you create new applications.">Server API reference</a></div> </div> </div><div class="topic reference nested1 api-method" id="FlowAPI-cancel_S_S"> <h2 class="title topictitle2" id="ariaid-title2">FlowAPI - cancel(String contextId, String reason)</h2> <div class="body refbody"><p class="shortdesc">Cancels a paused or running flow, subflow, or action.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-cancel_S_S__table_twb_vmn_p3b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 1. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e176">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e179">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e182">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e176 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e179 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e182 ">Sys_id of the execution details record for the flow, subflow, or action. Access the execution details by navigating to the Flow Executions tab in <span class="ph">Workflow Studio</span>, or pass the sys_id of the context record returned by the <span class="keyword apiname">startFlow()</span>, <span class="keyword apiname">startSubflow()</span>, or <span class="keyword apiname">startAction()</span> methods.<div class="note"><span class="notetitle">Note:</span> There might be a small delay in cancellation if the target context is running on a different node of the instance. Contexts running on the same node are cancelled immediately. Contexts running on another node must first wait for the cancellation to be forwarded to the appropriate node.</div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e176 ">reason</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e179 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e182 ">Optional. Reason for canceling the flow, subflow, or action. Appears in the <span class="ph uicontrol">Message</span> field of the Flow engine log entries [sys_flow_log] table.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-cancel_S_S__table_uwb_vmn_p3b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 2. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e248">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e251">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e248 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e251 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses the return value of the <span class="keyword apiname">startFlow()</span> method to cancel any long-running flows.</p> <pre class="pre codeblock"><code>(function() { var now_GR = new GlideRecord('incident'); now_GR.addQuery('number', 'INC0000050'); now_GR.query(); now_GR.next(); try { var inputs = {}; inputs['current'] = now_GR; // GlideRecord of table: inputs['table_name'] = 'incident'; // Starts the flow asynchronously. var result = sn_fd.FlowAPI.getRunner() .flow('global.myFlow') .inBackground() .withInputs(inputs) .run(); var contextId = result.getContextId(); var dateRun = result.getDate(); var domainUsed = result.getDomainId(); var flowName = result.getFlowObjectName(); var flowObjectType = result.getFlowObjectType(); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); // Call the cancel() method using the context Id returned from the startFlow() method sn_fd.FlowAPI.cancel(contextId, 'Flow took too long to execute.');</code></pre> </div> <div class="example"> <p class="p">This example cancels any flows named Test Flow.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("sys_flow_context"); now_GR.addQuery("name", "Test Flow"); now_GR.query(); while (now_GR.next()) { sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling Test Flows'); } </code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-executeAction"> <h2 class="title topictitle2" id="ariaid-title3">FlowAPI - executeAction(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Runs an action from a server-side script synchronously.</p> <div class="section"> <div class="p">Execute an action from within a business rule, script include, or any other server-side script. Actions run using this method run synchronously, so the method has access to outputs created by the action. Use <span class="ph uicontrol">startAction</span> to run an action asynchronously.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the action as the user who initiates the session.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeAction__table_jl1_gr1_jfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 3. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e383">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e386">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e389">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e383 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e386 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e389 ">The scope and name of the action to be executed, for example <code class="ph codeph">global.action_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e383 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e386 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e389 ">Name-value pairs that define action inputs. Use the input name, not the input label.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e383 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e386 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e389 "><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeAction__table_kl1_gr1_jfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 4. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e457">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e460">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e457 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e460 ">The action outputs.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">In this example, the script uses <span class="keyword apiname">sn_fd.FlowAPI.executeAction</span> to execute an action called actionforpassword2test in the global scope. A variable called inputs contains the inputs for the action. In this case, a name and password. The outputs for the action are stored in the outputs variable, which in this case, is an encrypted password object. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { var inputs = {}; inputs['name'] = ; // String inputs['password2'] = ; // Password (2 Way Encrypted) // Execute Synchronously: Run in foreground. Code snippet has access to outputs. // var timeout = ; //timeout in ms //sn_fd.FlowAPI.executeAction('global.actionforpassword2test', inputs, timeout) var outputs = sn_fd.FlowAPI.executeAction('global.actionforpassword2test', inputs); // Get Outputs: // Note: outputs can only be retrieved when executing synchronously. var output = outputs['output']; // Password (2 Way Encrypted) } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-executeActionQuick_S_O_N"> <h2 class="title topictitle2" id="ariaid-title4">FlowAPI - executeActionQuick(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Run an action from a server-side script synchronously from the current user session without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd"><span class="ph" id="FlowAPI-executeActionQuick_S_O_N__ph-quick-wait-action">This method does not support pausing the action to wait for conditions. Steps that pause for wait conditions such as Ask for Approval or Wait for Condition are not supported.</span></dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing an action to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeActionQuick_S_O_N__table_gx5_kcf_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 5. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e614">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e617">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e620">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e614 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e617 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e620 ">Scope and internal name of the action to execute. For example, <code class="ph codeph">global.action_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> actions.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e614 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e617 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e620 ">Name-value pairs that define action inputs. You can find the available action inputs and required data types under Inputs in the action outline. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e614 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e617 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e620 "><p class="p"><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></p> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeActionQuick_S_O_N__table_hx5_kcf_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 6. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e698">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e701">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e698 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e701 ">Object containing outputs defined by the action. You can find the outputs for the action under <span class="ph uicontrol">Outputs</span> in the action outline.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('57af7aec73d423002728660c4cf6a71c'); var inputs = {}; inputs['variable'] = grIncident; var outputs = sn_fd.FlowAPI.executeActionQuick('global.update_record_test', inputs); // Get Outputs: // Note: outputs can only be retrieved when executing synchronously. var output1 = outputs['output1']; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-executeDataStream_S_O"> <h2 class="title topictitle2" id="ariaid-title5">FlowAPI - executeDataStreamAction(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Runs a Data Stream action synchronously from a server-side script and returns a ScriptableDataStream object.</p> <div class="section"> <p class="p">For more information about Data Stream actions, see <a class="xref" href="../administer/integrationhub/concept/data-stream-actions.html" target="_blank" rel="noopener noreferrer">Data Stream actions and pagination</a>.</p> <div class="p"><div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">Always wrap data stream logic in a <code class="ph codeph">try/catch</code> block to catch errors. Always include a <code class="ph codeph">finally</code> statement that ends with the <span class="keyword apiname">close()</span> method from the <span class="keyword apiname">ScriptableDataStream</span> class to close the data stream and prevent performance issues.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeDataStream_S_O__table_oz4_hd3_z3b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 7. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e840">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e843">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e846">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e840 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e843 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e846 ">The scope and name of the Data Stream action to execute. For example, <code class="ph codeph">global.data_stream_action_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e840 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e843 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e846 ">Name-value pairs that define action inputs. Use the input name, not the input label. If the action does not have any inputs, do not include this parameter.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e840 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e843 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e846 ">Optional. Amount of time before the action times out. After the timeout expires, an exception is thrown. The timeout only applies to the <span class="keyword apiname">executeDataStreamAction</span> method, not to methods in the <span class="keyword apiname">ScriptableDataStream</span> class.<p class="p">Default: 30000, specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property</p> <p class="p">Unit: Milliseconds</p> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeDataStream_S_O__table_pz4_hd3_z3b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 8. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e924">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e927">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e924 ">ScriptableDataStream</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e927 ">An object used to iterate through items in the data stream. Use the methods in the <span class="keyword apiname">ScriptableDataStream</span> class to interact with this object. See <a class="xref" href="../../ScriptableDataStream/concept/ScriptableDataStreamAPI.html" title="The ScriptableDataStream API provides methods to interact with a stream of data.">ScriptableDataStream API</a>.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example creates an incident record for each item returned in the data stream.</p> <pre class="pre codeblock"><code>(function() { try { // Execute Data Stream Action. var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name'); // Process each item in the data stream while (stream.hasNext()) { // Get a single item from the data stream. var item = stream.next(); // Use the item. var now_GR = new GlideRecord('incident'); now_GR.setValue('number',item.id); now_GR.setValue('short_description',item.name); now_GR.insert(); // By default, this code snippet will terminate after 10 items. // Remove or modify this limit after testing your code. if (stream.getItemIndex() >= 9) { break; } } } catch (ex) { var message = ex.getMessage(); gs.error(message); } finally { stream.close(); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-executeFlow"> <h2 class="title topictitle2" id="ariaid-title6">FlowAPI - executeFlow(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Runs a flow from a server-side script synchronously.</p> <div class="section"> <div class="p">Execute a flow from within a business rule, script include, or any other server-side script. Flows run using this method run synchronously. Use <span class="ph uicontrol">startFlow</span> to run a flow asynchronously.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the flow as the user specified in flow properties.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeFlow__table_sgl_l42_kfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 9. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1062">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1065">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1068">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1062 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1065 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1068 ">The scope and name of the flow to be executed, for example <code class="ph codeph">global.flow_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1062 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1065 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1068 ">Name-value pairs that define trigger inputs. Use the input name, not the input label.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1062 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1065 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1068 "><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeFlow__table_tgl_l42_kfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 10. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1136">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1139">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1136 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1139 ">Normal operation produces no return value.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1136 ">Exception</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1139 ">The API throws an exception when a flow called synchronously pauses. <code class="ph codeph">The current execution is in the waiting state</code>. In most cases, the exception is removed when the flow resumes. However, the API cannot resume a flow that has been sent to a MID Server.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses sn_fd.FlowAPI.executeFlow to execute a global flow called test_flow. This flow is normally triggered when a record on the incident table is updated. Because you are activating the flow from a script, you must provide this information. The code creates an inputs variable that contains the current record, and the table for the record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { var inputs = {}; inputs['current'] = ; // GlideRecord of table: inputs['table_name'] = 'incident'; // Execute Synchronously: Run in foreground. // var timeout = ; //timeout in ms //sn_fd.FlowAPI.executeFlow('global.test_flow', inputs, timeout) sn_fd.FlowAPI.executeFlow('global.test_flow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-executeFlowQuick_S_O_N"> <h2 class="title topictitle2" id="ariaid-title7">FlowAPI - executeFlowQuick(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Runs a flow, subflow, action, or Data Stream action from a server-side script synchronously or asynchronously without creating execution details or other related records. Improves performance by eliminating record-keeping overhead.</span> <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Run as user</dt> <dd class="dd">This method runs the flow as the user who initiates the session. Setting the flow to run as the system user, or impersonating a user, is not supported.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd">This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.</dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing a flow to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeFlowQuick_S_O_N__table_rh4_qbf_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 11. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1311">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1314">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1317">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1311 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1314 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1317 ">Scope and internal name of the flow to execute. For example, <code class="ph codeph">global.flow_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> flows.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1311 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1314 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1317 ">Name-value pairs that define trigger inputs. You can find the available trigger inputs and required data types in the Trigger section of the flow. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1311 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1314 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1317 "><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeFlowQuick_S_O_N__table_sh4_qbf_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 12. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1394">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1397">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1394 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1397 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('ed92e8d173d023002728660c4cf6a7bc'); var inputs = {}; inputs['current'] = grIncident; inputs['table_name'] = 'incident'; sn_fd.FlowAPI.executeFlowQuick('global.test_quick_flow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-executeSubflow"> <h2 class="title topictitle2" id="ariaid-title8">FlowAPI - executeSubflow(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Runs an subflow from a server-side script synchronously.</p> <div class="section" id="ScriptableFlow-executeSubflow__section_xxh_4qc_mfb"> <div class="p">Execute a subflow from within a business rule, script include, or any other server-side script. Subflows run using this method run synchronously. Use <span class="ph uicontrol">startSubflow</span> to run an subflow asynchronously.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the flow as the user specified in flow properties.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeSubflow__table_jl1_gr1_jfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 13. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1515">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1518">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1521">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1515 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1518 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1521 ">The scope and name of the subflow to be executed, for example <code class="ph codeph">global.subflow_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1515 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1518 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1521 ">Name-value pairs that define subflow inputs. Use the input name, not the input label.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1515 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1518 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1521 "><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-executeSubflow__table_kl1_gr1_jfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 14. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1589">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1592">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1589 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1592 ">Object containing the subflow outputs.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1589 ">Exception</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1592 ">The API throws an exception when a flow called synchronously pauses. <code class="ph codeph">The current execution is in the waiting state</code>. In most cases, the exception is removed when the flow resumes. However, the API cannot resume a flow that has been sent to a MID Server.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">In this example, the script uses sn_fd.FlowAPI.executeSubflow to execute an subflow called subflowTest in the global scope. A variable called inputs contains the inputs for the subflow. In this case, a name and password. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code> (function() { try { var inputs = {}; inputs['name'] = ; // String inputs['password2'] = ; // Password (2 Way Encrypted) // Execute Synchronously: Run in foreground. // var timeout = ; //timeout in ms //sn_fd.FlowAPI.executeSubflow('global.subflowTest', inputs, timeout) var outputs = sn_fd.FlowAPI.executeSubflow('global.subflowTest', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-executeSubflowQuick_S_O_N"> <h2 class="title topictitle2" id="ariaid-title9">FlowAPI - executeSubflowQuick(String name, Map inputs, Number timeout)</h2> <div class="body refbody"><p class="shortdesc">Run a subflow from a server-side script synchronously from the current user session without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Run as user</dt> <dd class="dd">This method runs the flow as the user who initiates the session. Setting the flow to run as the system user, or impersonating a user, is not supported.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd">This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.</dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing a flow to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeSubflowQuick_S_O_N__table_znf_gcf_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 15. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1761">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1764">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1767">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1761 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1764 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1767 ">Scope and internal name of the subflow to execute. For example, <code class="ph codeph">global.subflow_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> subflows.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1761 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1764 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1767 ">Name-value pairs that define subflow inputs. You can find the available subflow inputs and required data types under Inputs in the subflow. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1761 ">timeout</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1764 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1767 "><span class="ph">Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the <span class="keyword parmname">com.glide.hub.flow_api.default_execution_time</span> system property. After the timeout expires, an exception is thrown.</span></td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-executeSubflowQuick_S_O_N__table_a4f_gcf_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 16. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1844">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1847">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1844 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1847 ">Object containing outputs defined by the subflow. You can find the outputs for the subflow under <span class="ph uicontrol">Subflow Inputs & Outputs</span> in the subflow outline.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('57af7aec73d423002728660c4cf6a71c'); var inputs = {}; inputs['variable'] = grIncident; var outputs = sn_fd.FlowAPI.executeSubflowQuick('global.test_quick_run_subflow', inputs); // Get Outputs: // Note: outputs can only be retrieved when executing synchronously. var output1 = outputs['output1']; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-getErrorMessage_S"> <h2 class="title topictitle2" id="ariaid-title10">FlowAPI - getErrorMessage(String contextId)</h2> <div class="body refbody"><p class="shortdesc">Returns the error messages produced by a flow, subflow, or action. This method cannot return messages from flows, subflows, or actions run with the quick() API.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getErrorMessage_S__table_zyb_hrm_25b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 17. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1925">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1928">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1931">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1925 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1928 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1931 ">The sys_id of the flow, subflow, or action whose error messages you want to get.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getErrorMessage_S__table_azb_hrm_25b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 18. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1968">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e1971">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1968 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e1971 ">The last operation run and the error message it produced.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example starts a global subflow called test_error_subflow and returns any error messages it produces. Normally, a single script does not both run a flow and then get its error messages. Typically, either another script or <span class="ph">Workflow Studio</span> would have already run the flow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { // Gather inputs to call flow var inputs = {}; inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task inputs['ah_comment'] ='Test Comment' ; // String // Call flow with known errors var contextId = sn_fd.FlowAPI.startSubflow('global.test_error_subflow', inputs); // Get flow error message var errormsg = sn_fd.FlowAPI.getErrorMessage(contextId); return errormsg; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); </code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Operation (test_error_flow.574033f6db6811102166e2291396199f.274073f6db6811102166e22913961908.0be0d916c31332002841b63b12d3ae13) failed with error: com.snc.process_flow.exception.OpException: Value of field record is not a GlideRecord at com.snc.process_flow.operation.FieldValue.getGlideRecord(FieldValue.java:145) at com.snc.process_flow.operation.CRUDOperation.getInputValidGlideRecord(CRUDOperation.java:54) at com.snc.process_flow.operation.RecordDeleteOperation.run(RecordDeleteOperation.java:26) at com.snc.process_flow.engine.Operation.execute(Operation.java:212) at com.snc.process_flow.engine.restricted_caller_access.ExecuteWithCallerAccessTracking.executeWithMetaStack(ExecuteWithCallerAccessTracking.java:31) at com.snc.process_flow.engine.ProcessEngine.executeOps(ProcessEngine.java:570) at com.snc.process_flow.engine.ProcessEngine.runInternal(ProcessEngine.java:476) at com.snc.process_flow.engine.ProcessEngine.run(ProcessEngine.java:462) at com.snc.process_flow.engine.ProcessAutomation.run(ProcessAutomation.java:86) at com.snc.process_flow.engine.GlideProcessAutomation.runSync(GlideProcessAutomation.java:155) at com.snc.process_flow.engine.GlideProcessAutomation.runWithDomain(GlideProcessAutomation.java:270) at com.snc.process_flow.engine.GlideProcessAutomation.lambda$runAsUserSync$1(GlideProcessAutomation.java:237) at com.snc.process_flow.engine.PFSessionClone.run(PFSessionClone.java:70) at com.snc.process_flow.engine.GlidePFSession.runPlanAsUserSession(GlidePFSession.java:42) at com.snc.process_flow.engine.GlideProcessAutomation.runAsUserSync(GlideProcessAutomation.java:235) at com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:330) at com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:309) at com.snc.process_flow.engine.ProcessHubEventHandler.doSendMessage(ProcessHubEventHandler.java:475) at com.snc.process_flow.engine.ProcessHubEventHandler.process(ProcessHubEventHandler.java:119) at com.snc.process_flow.engine.ProcessHubEventHandler.process(ProcessHubEventHandler.java:91) at com.snc.process_flow.engine.FlowEventManager.processEvents(FlowEventManager.java:122) at com.glide.job.EventHandlerJob.execute(EventHandlerJob.java:38) at com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:129) at com.snc.db.data_replicate.replicator.DataReplicationAdvisors.runInOriginatorContext(DataReplicationAdvisors.java:73) at com.glide.schedule.JobExecutor.lambda$inDataReplicationContext$2(JobExecutor.java:159) at com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:132) at com.glide.schedule.JobExecutor.execute(JobExecutor.java:116) at com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:338) at com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:220) at com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35) at com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:220) at com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:101)</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-getFlowStages_S"> <h2 class="title topictitle2" id="ariaid-title11">FlowAPI - getFlowStages(String scopedFlowName)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Return a JSON string containing the list of flow stages.</span></p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getFlowStages_S__table_x1j_n2v_v5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 19. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2058">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2061">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2064">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2058 ">scopedFlowName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2061 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2064 ">The application scope and name of the flow whose stages you want to get.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getFlowStages_S__table_y1j_n2v_v5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 20. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2101">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2104">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2101 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2104 ">JSON formatted string that lists the stages of the flow by their stage record values.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows getting the stages for the Service Catalog Item Request flow.</p> <pre class="pre codeblock"><code>(function() { try { // Name of flow with stages var flowName = "service_catalog_item_request"; // Get flow stages var flowStages = sn_fd.FlowAPI.getFlowStages(flowName); //Print JSON as info message gs.info(flowStages); return flowStages; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); </code></pre> <p class="p">Output:</p> <p class="p">The JSON string contains name-value pairs for a stage field. See for more information.</p> <pre class="pre codeblock"><code>[ { "label": "Manager Approval", "value": "manager_approval", "type": "standard", "duration": "1970-01-03 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 0 }, { "label": "Set current stage state to: [Error]", "value": "Set current stage state to: [Error]", "type": "error", "duration": "1970-01-01 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": false, "order": 0 }, { "label": "Dept. Head Approval", "value": "Dept. Head Approval", "type": "standard", "duration": "1970-01-03 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 1 }, { "label": "CIO Approval", "value": "CIO Approval", "type": "standard", "duration": "1970-01-03 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 2 }, { "label": "Order Fulfillment", "value": "Order Fulfillment", "type": "standard", "duration": "1970-01-05 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 3 }, { "label": "Backordered", "value": "Backordered", "type": "standard", "duration": "1970-01-15 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 4 }, { "label": "Deployment", "value": "Deployment", "type": "standard", "duration": "1970-01-02 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 5 }, { "label": "Request Cancelled", "value": "Request Cancelled", "type": "standard", "duration": "1970-01-01 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 6 }, { "label": "Completed", "value": "complete", "type": "standard", "duration": "1970-01-01 00:00:00", "states": { "pending": "Pending - has not started", "inprogress": "In progress", "skipped": "Skipped", "complete": "Completed", "error": "Error" }, "flow": "30f3d26187e92300e0ef0cf888cb0b91", "alwaysShow": true, "order": 7 } ]</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-getOutputs_S"> <h2 class="title topictitle2" id="ariaid-title12">FlowAPI - getOutputs(String contextId)</h2> <div class="body refbody"><p class="shortdesc">Returns the outputs of a completed action or subflow.</p> <div class="section"> <div class="p">You can use the return values from either the <span class="keyword apiname">startAction()</span> or<span class="keyword apiname">startSubflow()</span> methods as the contextId parameter.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getOutputs_S__table_lf5_5qq_nlb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 21. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2238">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2241">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2244">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2238 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2241 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2244 ">The sys_id of the action or subflow whose outputs you want to get.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getOutputs_S__table_mf5_5qq_nlb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 22. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2281">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2284">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2281 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2284 ">Object containing the action or subflow outputs.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example starts a global subflow called test_subflow, waits for the flow to finish, and then gets its output values. Normally, a single script does not both run a flow and then get its output values. Since a flow may not complete before the <span class="keyword apiname">getOutputs()</span> call, this example uses a wait time. Typically, either another script or <span class="ph">Workflow Studio</span> would have already run the flow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { // Gather inputs to call flow var inputs = {}; inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task inputs['ah_comment'] ='Test Comment' ; // String // Call flow var contextId = sn_fd.FlowAPI.startSubflow('global.test_subflow', inputs); // Wait for the flow to finish running // Get flow outputs var outputs = sn_fd.FlowAPI.getOutputs(contextId); var output1 = outputs['output1']; return output1; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); </code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-getRunner"> <h2 class="title topictitle2" id="ariaid-title13">FlowAPI - getRunner()</h2> <div class="body refbody"><p class="shortdesc">Returns a <span class="keyword apiname">ScriptableFlowRunner</span> builder object for a flow or action that you want to run.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getRunner__table_swx_cpp_rlb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 23. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2370">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2373">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2376">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2370 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2373 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2376 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getRunner__table_twx_cpp_rlb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 24. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2411">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2414">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2411 "><a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a></td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2414 ">Builder object used to run a <span class="ph">Workflow Studio</span> action, flow, or subflow.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example runs a flow synchronously.</p> <pre class="pre codeblock"><code> (function() { try { var inputs = {}; inputs['sys_id'] = '57af7aec73d423002728660c4cf6a71c'; // Pass the record's sys_id in as input. var result = sn_fd.FlowAPI.getRunner() // Create a ScriptableFlowRunner builder object. .action('global.markapproved') // Run the global scope action named markapproved. .inForeground() .inDomain('TOP/ACME') // Run the action from the TOP/ACME domain. .withInputs(inputs) .run(); // Run the action and return a FlowRunnerResult object. var contextId = result.getContextId(); // Retrieve the context ID from the result var dateRun = result.getDate(); var domainUsed = result.getDomainId(); // Retrieve the Domain ID from the result. var flowName = result.getFlowObjectName(); var flowObjectType = result.getFlowObjectType(); var outputs = result.getOutputs(); // Retrieve any outputs from the action execution. var newApprovalStatus = outputs['approval']; // Echo back the approval status for verification. } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); </code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-getStatus-S"> <h2 class="title topictitle2" id="ariaid-title14">FlowAPI - getStatus(String contextId)</h2> <div class="body refbody"><p class="shortdesc">Returns the status of a flow, subflow, or action.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getStatus-S__table_isj_glz_dbc" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 25. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2501">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2504">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2507">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2501 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2504 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2507 ">The sys_id of the flow, subflow, or action whose status you want to get.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-getStatus-S__table_jsj_glz_dbc" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 26. </span>Returns</span></caption><colgroup><col style="width:20%" /><col style="width:20%" /><col style="width:60%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2546">Parameter</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2549">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2552">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String></td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">JSON formatted string containing the current state of the flow, subflow, or action as name-value pairs. <pre class="pre codeblock"><code>{ "hasLookupError": Boolean, "errorMessage": "String", "contextStatus": {Object} }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.hasLookupError</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Flag that indicates whether there was an issue looking up the context status of the flow, subflow, or action.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": {Object} }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.errorMessage</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Error message returned by context lookup operation. This parameter is void when <span class="keyword parmname">hasLookupError</span> is false.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": {Object} }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">JSON formatted string containing state details about the queried flow, subflow, or action.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "NONE" } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.state</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">State of the flow, subflow, or action context. Some state values provide additional information in related parameters.<ul class="ul" id="FlowAPI-getStatus-S__ul_n2r_w11_2bc"><li class="li">COMPLETE provides additional information in the <span class="keyword parmname">errorState</span> parameter</li><li class="li">ERROR provides additional information in the <span class="keyword parmname">message</span> parameter</li><li class="li">CANCELLED provides additional information in the <span class="keyword parmname">canceledReason</span> parameter</li><li class="li">IN_PROGRESS provides additional information in the <span class="keyword parmname">isRunOnMid</span> parameter</li><li class="li">WAITING provides additional information in the <span class="keyword parmname">waitingOn</span> parameter</li></ul> <pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "NONE" } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.errorState</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Flow complete state produced by flow error handling. The API only generates this parameter when the flow, subflow, or action is in the COMPLETE state.<ul class="ul" id="FlowAPI-getStatus-S__ul_k5l_nb1_2bc"><li class="li">ERROR_CAUGHT</li><li class="li">ERROR_SKIPPED</li></ul> <pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "ERROR_CAUGHT" } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.message</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Error message returned by the flow, subflow, or action. The API only generates this parameter when the flow, subflow, or action is in the ERROR state.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "ERROR", "message": "Error: Error Message! (Process Automation.LOG; line 1)" } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.canceledReason</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Cancel message returned by the flow, subflow, or action. The API only generates this parameter when the flow, subflow, or action is in the CANCELLED state.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "CANCELLED", "canceledReason": "User has requested to stop executing the flow" } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.isRunOnMid</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Flag that indicates whether the flow, subflow, or action is run on a MID Server environment. The API only generates this parameter when the flow, subflow, or action is in the IN_PROGRESS state.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "IN_PROGRESS", "isRunOnMid": true } } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">Array</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">List of items that the current flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "TIMER", "endTime": 1713627497643 }, { "stepType": "WAIT_FOR_CONDITION_WITH_TIMEOUT", "table": "incident", "condition": "sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112", "endTime": 1713645497800 } ] } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.stepType</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">List of reasons why a flow, subflow, or action is waiting. The API only generates this parameter when the flow, subflow, or action is in the WAITING state.<ul class="ul" id="FlowAPI-getStatus-S__ul_jrw_td1_2bc"><li class="li">WAIT_FOR_CONDITION</li><li class="li">WAIT_FOR_CONDITION_WITH_TIMEOUT</li><li class="li">ASK_FOR_APPROVAL</li><li class="li">CREATE_TASK_WITH_WAIT</li><li class="li">TIMER</li><li class="li">SLA_TIMER</li><li class="li">SUBFLOW</li></ul> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.table</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Table name containing the record that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is WAIT_FOR_CONDITION, WAIT_FOR_CONDITION_WITH_TIMEOUT, ASK_FOR_APPROVAL, or CREATE_TASK_WITH_WAIT.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "WAIT_FOR_CONDITION", "table": "incident", "condition": "sys_id=1347723243200210338774d6ebb8f285^short_description=1238" } ] } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.condition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Query condition of the record that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is WAIT_FOR_CONDITION, WAIT_FOR_CONDITION_WITH_TIMEOUT, ASK_FOR_APPROVAL, or CREATE_TASK_WITH_WAIT.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "WAIT_FOR_CONDITION", "table": "incident", "condition": "sys_id=1347723243200210338774d6ebb8f285^short_description=1238" } ] } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.endTime</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">Integer</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">End time that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is WAIT_FOR_CONDITION_WITH_TIMEOUT, TIMER, or SLA_TIMER.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "SLA_TIMER", "endTime": 1713574610000 } ] } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.approvalRule</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">Approval rule that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is ASK_FOR_APPROVAL.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "ASK_FOR_APPROVAL", "table": "incident", "condition": "sys_id=3bd89703372002103387963174924b20^approvalINapproved,rejected,cancelled", "approvalRule": "ApprovesAnyU[a8f98bb0eb32010045e1a5115206fe3a,71826bf03710200044e0bfc8bcbe5d3b]" } ] } }</code></pre></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2546 "><String>.contextStatus.waitingOn.contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2549 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2552 ">The sys_id of the subflow that the flow or subflow is waiting on. The API only generates this parameter when the flow, or subflow is in the WAITING state and the stepType is SUBFLOW.<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "SUBFLOW", "contextId": "0f724aabd921021020291a665e07e44a" } ] } }</code></pre></td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example runs a flow containing Do the following in parallel flow logic. Normally, a single script does not both run a flow and then get its error messages. Typically, either another script or <span class="ph">Workflow Studio</span> would have already run the flow.</p> <pre class="pre codeblock"><code>(function() { try { var result = sn_fd.FlowAPI.getRunner() // Create a ScriptableFlowRunner builder object. .flow('global.test_do_in_parallel') // Run the global scope flow named do_in_parallel. .run(); // Run the action and return a FlowRunnerResult object. var contextId = result.getContextId(); // Retrieve the context ID from the result var flowStatus = sn_fd.FlowAPI .getStatus(contextId); // Retrieve any outputs from the action execution. return flowStatus; } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> <div class="p">Output:<pre class="pre codeblock"><code>{ "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "stepType": "TIMER", "endTime": 1713627497643 }, { "stepType": "WAIT_FOR_CONDITION_WITH_TIMEOUT", "table": "incident", "condition": "sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112", "endTime": 1713645497800 } ] } }</code></pre></div> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-hasApprovals_S"> <h2 class="title topictitle2" id="ariaid-title15">FlowAPI - hasApprovals(String scopedFlowName)</h2> <div class="body refbody"><p class="shortdesc">Checks if a flow within a give scope contains any Ask for Approval actions.</p> <div class="section"> <p class="p">The <span class="keyword apiname">hasApprovals()</span> method determines if a flow within a given scope contains any Ask for Approval actions. This method also checks if any Ask for Approval actions within the flow are nested under If flow logic blocks. For more information, see <a class="xref" href="../administer/flow-designer/reference/ask-approval-flow-designer.html" target="_blank" rel="noopener noreferrer">Ask for Approval actions</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-hasApprovals_S__table_w1d_dz2_vlb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 27. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2929">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2932">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2935">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2929 ">scopedFlowName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2932 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2935 ">Scope and internal name of the flow to execute. For example, <code class="ph codeph">global.flow_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> flows.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-hasApprovals_S__table_x1d_dz2_vlb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 28. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2981">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e2984">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2981 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e2984 ">Returns one of the following string values:<ul class="ul" id="FlowAPI-hasApprovals_S__ul_fx1_fdf_vlb"><li class="li">ALWAYS: The flow contains an Ask for Approval action that isn't nested within a conditional <code class="ph codeph">If</code> flow logic block.</li><li class="li">CONDITIONALLY: The flow contains an Ask for Approval action that is nested within a conditional <code class="ph codeph">If</code> flow logic block.</li><li class="li">NO: The flow doesn't contain any Ask for Approval actions.</li><li class="li">UNKNOWN: There was a compiler error, and the system can't determine whether the flow contains any Ask for Approval actions.</li></ul> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">The following example checks if the <span class="keyword apiname">example_flow</span> flow within the <span class="keyword apiname">global</span> scope contains any Ask for Approval actions and logs the result.</p> <pre class="pre codeblock"><code>(function() { try { var result = sn_fd.FlowAPI.hasApprovals('global.example_flow'); gs.log('Result: ' + result); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-restartFlowFromContext_S_O"> <h2 class="title topictitle2" id="ariaid-title16">FlowAPI - restartFlowFromContext(String ContextId, Map providedInputs)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Restarts a flow, subflow, or action that was run in the background. You can provide new inputs or omit them to reuse the previously provided inputs.</span></p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-restartFlowFromContext_S_O__table_wqp_1sv_v5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 29. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3089">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3092">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3095">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3089 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3092 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3095 ">The sys_id of the flow, subflow, or action you want to restart. This flow, subflow, or action must have run in background and have an associated sysevent record.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3089 ">providedInputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3092 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3095 ">Optional. Map object containing the name-value pairs that define replacement inputs for the flow, subflow, or action. If you omit or provide a null value for this parameter, the flow, subflow, or action runs using the previously provided inputs.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-restartFlowFromContext_S_O__table_twx_cpp_rlb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 30. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3144">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3147">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3144 ">ScriptableFlowRunnerResultsScoped</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3147 ">Object containing the execution details of a <span class="ph">Workflow Studio</span> action, flow, or subflow.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">Restarts a sample flow that has a record-based trigger on the Incident table. The original flow used sample incident INC0008112 as an input. When the flow restarts it instead uses sample incident INC0008111 as an input.</p> <pre class="pre codeblock"><code>(function() { try { var flowContextID = '4216396ffd7d11107edcf07204c30fd5'; // sys_id of sys_flow_context record var oldIncidentRecord = '552c48888c033300964f4932b03eb092'; // sys_id of INC0008112 var newIncidentRecord = 'a83820b58f723300e7e16c7827bdeed2'; // sys_id of INC0008111 var inputs = {}; var gr = new GlideRecord('incident'); // Create new incident object gr.get(newIncidentRecord); // Get GlideRecord object for INC0008111 inputs['current'] = gr; // Set new Incident record as input inputs['table_name'] = 'incident'; // Set table name to Incident var result = sn_fd.FlowAPI.getRunner() // Create a ScriptableFlowRunner builder object. .restartFlowFromContext(flowContextID, inputs); // Restart flow with new inputs. var contextId = result.getContextId(); // Retrieve the context ID from the result var dateRun = result.getDate(); gs.info(contextId + ' ' + dateRun); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); </code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-scheduleCancel_S_S_I"> <h2 class="title topictitle2" id="ariaid-title17">FlowAPI - scheduleCancel(String contextId, String reason, Integer delaySeconds)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Schedule a system event in the Flow Engine Queue to cancel a flow that is in the in progress, presumed interrupted, or waiting state after a delay.</span></p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-scheduleCancel_S_S_I__table_mrg_gpn_v5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 31. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3228">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3231">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3234">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3228 ">contextId</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3231 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3234 ">Sys_id of the execution details record for the flow, subflow, or action. The target flow, subflow, or action must be in the in progress, presumed interrupted, or waiting state. Access the execution details by navigating to the Flow Executions tab in <span class="ph">Workflow Studio</span>, or pass the sys_id of the context record returned by the method.<div class="note"><span class="notetitle">Note:</span> There might be a small delay in cancellation if the target context is running on a different node of the instance. Contexts running on the same node are cancelled immediately. Contexts running on another node must first wait for the cancellation to be forwarded to the appropriate node.</div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3228 ">reason</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3231 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3234 ">Reason for canceling the flow, subflow, or action. Appears in the <span class="ph uicontrol">Message</span> field of the Flow engine log entries [sys_flow_log] table.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3228 ">delaySeconds</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3231 ">Integer</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3234 ">Optional. Number of seconds to wait before processing a cancellation event in the Flow Engine Queue. If you omit this parameter, the method uses the default value of 1 second.<p class="p">You can use this parameter to avoid the performance impact of scheduling the cancellation of thousands of flow contexts at the same time. Rather than run all cancellations simultaneously, schedule a batch of flow cancellations with a delay. Alternatively, you could use the delay as a time out value for an asynchronous flow.</p> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-scheduleCancel_S_S_I__table_nrg_gpn_v5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 32. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3305">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3308">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3305 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3308 "> </td></tr></tbody></table> </div> </div> <div class="example" id="FlowAPI-scheduleCancel_S_S_I__example_c5c_tqn_v5b"> <p class="p">This example uses the return value of the <span class="keyword apiname">startFlow()</span> method to schedule the cancellation of any long-running flows.</p> <pre class="pre codeblock"><code>(function() { var now_GR = new GlideRecord('incident'); now_GR.addQuery('number', 'INC0000050'); now_GR.query(); now_GR.next(); try { var inputs = {}; inputs['current'] = now_GR; // GlideRecord of table: inputs['table_name'] = 'incident'; // Starts the flow asynchronously. var contextId = sn_fd.FlowAPI.startFlow('global.myFlow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })(); // Call the scheduleCancel() method using the context Id returned from the startFlow() method sn_fd.FlowAPI.scheduleCancel(contextId, 'Flow took too long to execute.', 60);</code></pre> </div> <div class="example" id="FlowAPI-scheduleCancel_S_S_I__example_d5c_tqn_v5b"> <p class="p">This example schedules the cancellation of any flows named Test Flow.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("sys_flow_context"); now_GR.addQuery("name", "Test Flow"); now_GR.query(); while (now_GR.next()) { sn_fd.FlowAPI.scheduleCancel(now_GR.getUniqueValue(), 'Canceling Test Flows', 60); } </code></pre> </div> <div class="example" id="FlowAPI-scheduleCancel_S_S_I__example_rxs_td3_fvb"> <p class="p">This example uses the delaySeconds parameter to run flow cancellation jobs in batches. Use batches to cancel thousands of flow contexts.</p> <pre class="pre codeblock"><code>var delaySeconds = 1; for (var i; i < sys_flow_context.length; ++i) { if (i % 100 === 0) { delaySeconds = delaySeconds + 60; } var contextId = sys_flow_context[i]; var reason = "Example reason"; sn_fd.FlowAPI.scheduleCancel(contextId, reason, delaySeconds); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-glideActionUtil-setEncryptedOutput"> <h2 class="title topictitle2" id="ariaid-title18">FlowAPI - setEncryptedOutput(String password)</h2> <div class="body refbody"><p class="shortdesc">Builds password2 values inside a script step.</p> <div class="section"> <p class="p">Identify an encrypted password2 value returned from a GlideRecord, enabling the system to display the value as a masked password rather than an encrypted string.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-glideActionUtil-setEncryptedOutput__table_o5h_fyl_mfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 33. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3420">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3423">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3426">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3420 ">password</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3423 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3426 ">Encrypted password2 value.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-glideActionUtil-setEncryptedOutput__table_p5h_fyl_mfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 34. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3463">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3466">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3463 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3466 ">Encrypted password2 value, recognised by the engine as a password value.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example returns value of a password2 field from a user record and stores in in a variable. This variable is passed into the setEncryptedOutput method, which is called using sn_fd.GlideActionUtil.setEncryptedOutput. The instance recognises the returned value as a password.</p> <pre class="pre codeblock"><code>(function execute(inputs, outputs) { // ...code... var now_GR = new GlideRecord('sys_user'); now_GR.addQuery('first_name' , 'Abel'); now_GR.query(); now_GR.next(); var pwVal = now_GR.getValue('pw2'); outputs['usedSetEncrypted'] = sn_fd.GlideActionUtil.setEncryptedOutput(pwVal); outputs['justSetDirectly'] = pwVal; })(inputs, outputs);</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-startAction"> <h2 class="title topictitle2" id="ariaid-title19">FlowAPI - startAction(String name, Map inputs)</h2> <div class="body refbody"><p class="shortdesc">Runs an action from a server-side script asynchronously.</p> <div class="section"> <div class="p">Execute an action from within a business rule, script include, or any other server-side script. Actions run using this method run asynchronously, so scripts using this method do not have access to any outputs created by the action. Use <span class="ph uicontrol">executeAction</span> to run an action synchronously and access the outputs it generates.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the action as the user who initiates the session.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startAction__table_r5n_p2d_hfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 35. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3587">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3590">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3593">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3587 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3590 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3593 ">The scope and name of the action to be executed, for example <code class="ph codeph">global.action_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3587 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3590 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3593 ">Name-value pairs that define action inputs. Use the input name, not the input label.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startAction__table_s5n_p2d_hfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 36. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3645">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3648">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3645 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3648 ">Sys Id of the context record for the action. Access the context record by navigating to the Flow Executions tab in <span class="ph">Workflow Studio</span>, selecting a flow execution, and clicking <span class="ph uicontrol">Open Context Record</span>.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses sn_fd.FlowAPI.startAction to execute an action called add_comment in the sn_itsm_spoke scope. The inputs object contains a target record and a comment to add to that record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { var inputs = {}; inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task inputs['ah_comment'] ='Test Comment' ; // String var contextId = sn_fd.FlowAPI.startAction('sn_itsm_spoke.add_comment', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-startActionQuick_S_O"> <h2 class="title topictitle2" id="ariaid-title20">FlowAPI - startActionQuick(String name, Map inputs)</h2> <div class="body refbody"><p class="shortdesc">Runs an action from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd"><span class="ph" id="FlowAPI-startActionQuick_S_O__ph-quick-wait-action">This method does not support pausing the action to wait for conditions. Steps that pause for wait conditions such as Ask for Approval or Wait for Condition are not supported.</span></dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing an action to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startActionQuick_S_O__table_zww_lff_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 37. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3805">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3808">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3811">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3805 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3808 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3811 ">Scope and internal name of the action to execute. For example, <code class="ph codeph">global.action_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> actions.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3805 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3808 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3811 ">Name-value pairs that define action inputs. You can find the available action inputs and required data types under Inputs in the action outline. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startActionQuick_S_O__table_axw_lff_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 38. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3872">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3875">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3872 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3875 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('57af7aec73d423002728660c4cf6a71c'); var inputs = {}; inputs['variable'] = grIncident; sn_fd.FlowAPI.startActionQuick('global.update_record_test', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-startFlow"> <h2 class="title topictitle2" id="ariaid-title21">FlowAPI - startFlow(String name, Map inputs)</h2> <div class="body refbody"><p class="shortdesc">Runs a flow from a server-side script.</p> <div class="section"> <div class="p">Execute a flow from within a business rule, script include, or any other server-side script. Flows executed with this method run asynchronously.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the flow as the user specified in flow properties.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startFlow__table_myv_pmw_gfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 39. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3989">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3992">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e3995">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3989 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3992 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3995 ">The scope and name of the flow to be executed, for example <code class="ph codeph">global.flow_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3989 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3992 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e3995 ">Name-value pairs that define trigger inputs. Use the input name, not the input label.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startFlow__table_nyv_pmw_gfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 40. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4047">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4050">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4047 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4050 ">Sys Id of the context record for the flow. Access the context record by navigating to the Flow Executions tab in <span class="ph">Workflow Studio</span>, selecting a flow execution, and clicking <span class="ph uicontrol">Open Context Record</span>.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses sn_fd.FlowAPI.startFlow to execute a global flow called test_flow. The code creates an inputs variable that contains inputs required by the flow. In this case, the current record and the table for the record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { var now_GR = new GlideRecord('incident'); now_GR.addQuery('number', 'INC0009009'); now_GR.query(); now_GR.next(); try { var inputs = {}; inputs['current'] = now_GR; // GlideRecord of table: Incident inputs['table_name'] = 'incident'; var contextId = sn_fd.FlowAPI.startFlow('global.test_flow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-startFlowQuick_S_O"> <h2 class="title topictitle2" id="ariaid-title22">FlowAPI - startFlowQuick(String name, Map inputs)</h2> <div class="body refbody"><p class="shortdesc">Runs a flow from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Run as System user</dt> <dd class="dd">This method runs the flow as the System user. Setting the flow to run as the user who initiates the session, or impersonating a user, is not supported.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd">This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.</dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing a flow to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startFlowQuick_S_O__table_wxm_hff_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 41. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4215">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4218">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4221">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4215 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4218 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4221 ">Scope and internal name of the flow to execute. For example, <code class="ph codeph">global.flow_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> flows.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4215 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4218 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4221 ">Name-value pairs that define trigger inputs. You can find the available trigger inputs and required data types in the Trigger section of the flow. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startFlowQuick_S_O__table_xxm_hff_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 42. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4282">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4285">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4282 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4285 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('ed92e8d173d023002728660c4cf6a7bc'); var inputs = {}; inputs['current'] = grIncident; inputs['table_name'] = 'incident'; sn_fd.FlowAPI.startFlowQuick('global.test_quick_flow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="ScriptableFlow-startSubFlow"> <h2 class="title topictitle2" id="ariaid-title23">FlowAPI - startSubflow(String name, Map input)</h2> <div class="body refbody"><p class="shortdesc">Runs a subflow from a server-side script.</p> <div class="section"> <div class="p">Execute a subflow from within a business rule, script include, or any other server-side script. Subflows run using this method run asynchronously Scripts that include this method do not have access to outputs created by the flow. Use <span class="ph uicontrol">executeSubflow</span> to run a subflow synchronously and access the outputs it generates.<div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This method runs the flow as the user specified in flow properties.</span></div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startSubFlow__table_jwt_b1d_hfb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 43. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4405">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4408">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4411">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4405 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4408 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4411 ">The scope and name of the subflow to be executed, for example <code class="ph codeph">global.subflow_name</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4405 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4408 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4411 ">Name-value pairs that define subflow inputs. Use the input name, not the input label.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ScriptableFlow-startSubFlow__table_kwt_b1d_hfb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 44. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4463">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4466">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4463 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4466 ">Sys Id of the context record for the subflow. Access the context record by navigating to the Flow Executions tab in <span class="ph">Workflow Studio</span>, selecting a flow execution, and clicking <span class="ph uicontrol">Open Context Record</span>.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses <span class="keyword apiname">sn_fd.FlowAPI.startSubflow</span> to execute a global flow called test_subflow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.</p> <pre class="pre codeblock"><code>(function() { try { var inputs = {}; inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task inputs['ah_comment'] ='Test Comment' ; // String var contextId = sn_fd.FlowAPI.startSubflow('global.test_subflow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="FlowAPI-startSubflowQuick_S_O"> <h2 class="title topictitle2" id="ariaid-title24">FlowAPI - startSubflowQuick(String name, Map inputs)</h2> <div class="body refbody"><p class="shortdesc">Runs a subflow from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. <span class="ph">Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.</span></p> <div class="section"> <div class="p"><dl class="dl"> <dt class="dt dlterm">Reporting & records generated</dt> <dd class="dd">This method does not create execution details and context records, regardless of <span class="ph">Workflow Studio</span> settings.</dd> <dt class="dt dlterm">Run as System user</dt> <dd class="dd">This method runs the flow as the System user. Setting the flow to run as the user who initiates the session, or impersonating a user, is not supported.</dd> <dt class="dt dlterm">Wait support</dt> <dd class="dd">This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.</dd> <dt class="dt dlterm">MID Server support</dt> <dd class="dd">This method does not support pausing a flow to run from a MID Server.</dd> </dl> </div> <div class="note"><span class="notetitle">Note:</span> <span class="ph">This API is replaced by <a class="xref" href="../../ScriptableFlowRunnerScoped/concept/ScriptableFlowRunnerScopedAPI.html" title="Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.">ScriptableFlowRunner</a>, which deprecates the existing methods used to build objects and execute <span class="ph">Workflow Studio</span> flows and actions. Use the <span class="keyword apiname">getRunner()</span> method in the <span class="keyword apiname">FlowAPI</span> class to return a ScriptableFlowRunner object and use the associated methods. Use the <span class="keyword apiname">ScriptableFlowRunner</span> methods if you need to support domain separation.</span></div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startSubflowQuick_S_O__table_zx2_jff_1hb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 45. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4634">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4637">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4640">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4634 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4637 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4640 ">Scope and internal name of the subflow to execute. For example, <code class="ph codeph">global.subflow_name</code>. Locate the <span class="ph uicontrol">Internal name</span> field in the list of <span class="ph">Workflow Studio</span> subflows.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4634 ">inputs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4637 ">Map</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4640 ">Name-value pairs that define subflow inputs. You can find the available subflow inputs and required data types under Inputs in the subflow. Use the input name, not the input label. For example, <code class="ph codeph">{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}</code>.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="FlowAPI-startSubflowQuick_S_O__table_ay2_jff_1hb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 46. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4701">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d869483e4704">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4701 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d869483e4704 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>(function() { try { var grIncident = new GlideRecord('incident'); grIncident.get('57af7aec73d423002728660c4cf6a71c'); var inputs = {}; inputs['variable'] = grIncident; sn_fd.FlowAPI.startSubflowQuick('global.test_quick_run_subflow', inputs); } catch (ex) { var message = ex.getMessage(); gs.error(message); } })();</code></pre> </div> </div> </div> </div> </body></html></div>