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

Alexander Grisb
Kilo Guru

Are you getting any error message with this? It looks like you have it wrapped in a try catch - If any of the code inside fails at any time you should get an error message. You should prefix your error message with something so it's easier to find, but to me, it looks like this should work, however, in this post, it says it may take a long time if approvals are required. https://developer.servicenow.com/blog.do?p=/post/new-for-developers-in-madrid-flow-apis/. Also, if you wrapped it in a if statement, I would check to make sure your condition is true.

It looks like it's this error:

GlideRecord input is for incorrect table

 

I've got logs to ensure I am in the if statement, so perhaps this error will help us pinpoint the cause?

Christian_
Tera Guru

Hello, 

Is your flow named : flow_name, or is this only as an example here?

Ref. sn_fd.FlowAPI.startFlow('global.flow_name', inputs);

I do have the correct flow name in the call, but I did edit it for the community as it's for a client.