Launching Service Catalog Triggered Flow via Workflow Script

Chris Schuh
Giga Contributor

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.

10 REPLIES 10

Have you tried to execute your code via background script? 

 

When I try that approach, I get this error message:

 

*** Script: CHRIS ERROR = undefined: no thrown error

OK, are you sure you have a valid input in your background script?
Current (current.sys_id) is replaced with an actual record.

Nice catch - I hardcoded the sys ID in the background script and now it's giving a "Not authorized" error message.

Prateek kumar
Mega Sage

is your flow name flow_name??

As per the docs it should be your actual flow name

find_real_file.png


Please mark my response as correct and helpful if it helped solved your question.
-Thanks