- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 03:34 PM
Hi, this is in relation to the following post: REST Activity error handling (Eureka)
I responded to the thread, but I don't think anyone's looking at it again, and I bit under the gun...
Basically, my question is this:
Can you explain why this works (and it does work for me), exactly?
var history = new GlideRecord('wf_history');
history.get(activity.previous_activity);
workflow.scratchpad.RESTError = history.output;
Specifically, the 2nd line and the "previous_activity" part. I know line two is get values from the activity field in the wf_history table, but how is properly matching up to the current request item with .previoius_activity?
I'm using this on a workflow script to pull in the XML (stored in wf_history table output field) of a SOAP response into a variable based on the above code:
var history = new GlideRecord('wf_history');
history.get(activity.previous_activity);
current.variables.aws_xml = history.output;
Will this always pull in the correct output into the correct RITM or RFTASK? Are there other activity.* calls like activity.current_activity?
Thanks!
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 08:24 AM
If the activities are "far apart"... don't know. I might consider using the workflow scratchpad at that point.
http://wiki.servicenow.com/index.php?title=Using_the_Workflow_Scratchpad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 05:05 PM
Not sure. I'll see if I can dig up something and post it here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 07:53 AM
Thanks for your help!
Oh, I do have a follow up question...
I moved this script to a task further up(down?) the workflow. will activity.previous_activity still pick up the right element, the output, since that won't be the most immediate activity, I think? Or is there a way to step back further with previous_activity to select the right previous activity? Make sense?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 08:24 AM
If the activities are "far apart"... don't know. I might consider using the workflow scratchpad at that point.
http://wiki.servicenow.com/index.php?title=Using_the_Workflow_Scratchpad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 09:50 AM
Yeah, it's not far apart at all. It's just one more step forward in the flow. And it's a very specific call that only happens one time in the workflow. I was thinking something like this might work:
var history = new GlideRecord('wf_history');
history.get(activity.previous_activity, "Call AWS Account Service"); —> That's the name of the activity btw I need the output for.
current.variables.aws_xml = history.output;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:12 PM
So, this gets weirder. I took your advice and used the scratchpad like you suggested. The workflow has two tasks.
On task 1, the code I used was:
storeIt();
function storeIt() {
var history = new GlideRecord('wf_history');
history.get(activity.previous_activity);
current.variables.aws_xml = history.output;
history.update();
workflow.scratchpad.aws_xml = gr.getUniqueValue();
}
On task 2, I used:
var history = new GlideRecord('wf_history');
history.get( workflow.scratchpad.aws_xml );
And it pulls in the value successfully into the aws_xml variable. But, now, instead of task 1 opening, then task 2, now both tasks open simultaneously. If I take the code out, the tasks go back to opening sequentially instead of simultaneously. Does using the scratchpad affect the workflow? I'm I doing something wrong or need to add a condition since I'm using the scratchpad?
Thanks!