Launching Service Catalog Triggered Flow via Workflow Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 11:16 AM
Hi Everyone,
I am currently trying to launch a flow via a script in a Workflow. I have used the code snippets and the examples found here, but for some reason the flow just won't start.
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=FlowScoped-startAsync_S_GR
Here's an example of the code:
(function() {
try {
var glideRecordInput = new GlideRecord('sc_req_item');
glideRecordInput.get(current.sys_id);
var inputs = {};
inputs['request_item'] = glideRecordInput; // GlideRecord of table: sc_req_item
inputs['table_name'] = glideRecordInput.getTableName();
// Start Asynchronously: Uncomment to run in background.
sn_fd.FlowAPI.startFlow('global.flow_name', inputs);
// Execute Synchronously: Run in foreground.
//sn_fd.FlowAPI.executeFlow('global.flow_name', inputs);
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
I have the above code wrapped in an if statement, as I want to only trigger the flow to run in certain conditions. Any help would be greatly appreciated.
- Labels:
-
Request Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 12:11 PM
Have you tried to execute your code via background script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 03:50 PM
When I try that approach, I get this error message:
*** Script: CHRIS ERROR = undefined: no thrown error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 04:10 PM
OK, are you sure you have a valid input in your background script?
Current (current.sys_id) is replaced with an actual record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 04:34 PM
Nice catch - I hardcoded the sys ID in the background script and now it's giving a "Not authorized" error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 11:42 AM