- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:16 AM
Hello everyone,
I have a subflow which is submitting a Catalog Item and outputting the Request details (Request Number and Sys ID):
As you can see below, subflow output is returning the correct thing:
This is the way I am calling the flow (this is practically using the boiler plate ServiceNow provide (Create Code Snippet):
addToCart: function(){
try {
gs.info('cris flow'); // shows in logs
var currUser = gs.getUserID();
var inputs = {};
inputs['cart'] = this.getParameter('sysparm_citem'); // String
inputs['requested_for'] = this.getParameter('sysparm_reqfor'); // String
inputs['opened_by'] = currUser; // String
gs.info('cris flow mid'); // shows in logs
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow('global.acosubmitcatitem').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.acosubmitcatitem').inForeground().withInputs(inputs).run();
gs.info('cris flow result' + result); //does NOT show in logs
var outputs = result.getOutputs(); // does NOT get set
gs.info('cris flow output ' + outputs['request']); //does NOT show in logs
return outputs; // client side receives null
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
}
The subflow creates the Request and Request Item fine and returns the correct outputs, but I am not able to pass back the sys_id of the newly created Request to the client side (using the AJAX above) Since I am not able to grab the flow outputs in the script include because the 'getOutputs()' is receiving nothing.
Any ideas why this might be occuring? One thing that might be worth mentioning is that the flow is in global scope and the script include is scoped in my app.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 05:47 AM
Quick update on this one:
The try-catch was giving an error 'com.glide.plan.runners.FlowObjectAPIException: The current execution is in the waiting state'. This is because my subflow had an explicit 3 second wait, so the getOutputs (presumably because this method will not wait) was not returning and passing null back to client-side.
I have added further logic client-side to lookup the newly created Request AFTER the first AJAX completes, this seems to have fixed it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:41 AM
Hi
the image is broken and it is not really clear what the source code represents.
I recommend testing subflow invocation in a script console first and then embed it in overall solution.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:48 AM
try to use "executesubflowQuick" or "executeSubflow", Start subflow from your code something like this:
var outputs = sn_fd.FlowAPI.executeSubflowQuick('global.acosubmitcatitem', inputs);
var output1 = outputs['output1'];
Refer this link for more details
https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/sn_fd-namespace/ScriptableFlowAPI#FlowAPI-executeSubflowQuick_S_O_N
https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/sn_fd-namespace/ScriptableFlowAPI#ScriptableFlow-executeSubflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 05:47 AM
Quick update on this one:
The try-catch was giving an error 'com.glide.plan.runners.FlowObjectAPIException: The current execution is in the waiting state'. This is because my subflow had an explicit 3 second wait, so the getOutputs (presumably because this method will not wait) was not returning and passing null back to client-side.
I have added further logic client-side to lookup the newly created Request AFTER the first AJAX completes, this seems to have fixed it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:36 AM
Hi Cris,
May I please request you to share the solution as I am having the same issue.
Thanks
Mohit K