- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 10:48 AM
I am needing to start a workflow for every cmdb_ci_appl that is up for review. I have created a scheduled job that gets the list of
applications to review. As I loop through them I want to start a workflow.
I am getting the correct application and I see the log entry in the while. I never see the workflow start (via Active Contexts) and no
errors in the log.
What am I doing wrong in the w.startFlow call?
Thanks,
Tina
function reviewApplications(){
//var arrUtil = new ArrayUtil(); //set up array to find all pending approvals for users
var answer = [];
var app = new GlideRecord('cmdb_ci_appl'); //set up variable to retrieve approvals that are pending
app.addEncodedQuery("nameLIKEoracle");
app.query(); //retrieve all approvals that meet our query
while(app.next()){ // step through the approvals one by one
gs.log('CAL - App ' + app.name);
var w = new Workflow();
var vars = {};
var context = w.startFlow('03efcb0337dfba0056d9a9c2b3990e53', current, current.operation() , vars);
//In stead of current you can give glide record: gr (it must be glide record)
//id: The sys_id of the workflow to start. This sys_id refers to table wf_workflow.
//operation: insert or update
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 11:08 AM
Hi Christina,
"current" is undefined here. This line is likely throwing an error.
var context = w.startFlow('03efcb0337dfba0056d9a9c2b3990e53', current, current.operation() , vars);
Try changing it to:
var context = w.startFlow('03efcb0337dfba0056d9a9c2b3990e53', app, app.operation() , vars);
Suggestion: whenever writing scheduled jobs, test them first in Scripts - Background to ensure they work as expected.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 11:08 AM
Hi Christina,
"current" is undefined here. This line is likely throwing an error.
var context = w.startFlow('03efcb0337dfba0056d9a9c2b3990e53', current, current.operation() , vars);
Try changing it to:
var context = w.startFlow('03efcb0337dfba0056d9a9c2b3990e53', app, app.operation() , vars);
Suggestion: whenever writing scheduled jobs, test them first in Scripts - Background to ensure they work as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 11:27 AM
I actually found in the completed context that the workflow HAD been running. 'current' and 'app' both worked.
But the workflow was finishing so quick (not updating and waiting like it should) that I didn't realize it. Another
question.. when the workflow is running how does it now the record (application) it's running for. I thought the passing of 'app'
was what told it. How would I reference the application record from within the workflow scripts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 05:40 AM
Hi Christina,
The second argument to startFlow() is what tells it which record. It contains all the attributes (including sys_id) of the record being processed.