- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 11:07 AM
Hello,
I have a Scripted REST API that kicks off a workflow. That workflow will be doing some orchestration activities and then spits out some return values.
if( request.body.data.user_id){
var wfInputs = {};
wfInputs.u_ad_hostname='000.000.000.000';
wfInputs.u_user_name=request.body.data.user_id;
var gr = new GlideRecord('wf_workflow');
gr.addQuery('name', 'myWorkflow');
gr.query();
if(gr.next()){
var wf = new Workflow();
var workflowId = '' + gr.sys_id;
var wfContext = wf.startFlow(workflowId, null, 'update',wfInputs);
var responseBody = wf.getReturnValue(wfContext);
}
}
The code works except the code processes quicker then the workflow does which means the response body will always be empty. Is there a way for the script to just wait until the workflow is finished before it continues? Can I send some kind of signal from the workflow?
thanks,
Martin
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 01:09 PM
I think your return values should be at the end of your workflow. I am not sure how many activities you are doing during the process but you need to wait until the workflow is finished to send the values. The timer was to avoid performance issues when two scripts are running at the same time but I think you don't need it in this case.
Regards,
Pedro Lopez
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 11:11 AM
I had something similar and my solution was to add a timer in the workflow, just wait around 10 seconds.
I hope this helps.
Regards,
Pedro Lopez
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 11:37 AM
Hi Pedro,
When adding the timer did you experience any issues with the return value? My return value no matter how long I make the timer is always null. I set a log statement in the workflow and in the script so I know they are happening in the right order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 01:09 PM
I think your return values should be at the end of your workflow. I am not sure how many activities you are doing during the process but you need to wait until the workflow is finished to send the values. The timer was to avoid performance issues when two scripts are running at the same time but I think you don't need it in this case.
Regards,
Pedro Lopez
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 11:58 AM
Thank you Pedro, I was able to figure it out. The return value was always null so I created a new Gliderecord to query the context and get the return value from there.