- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 10:33 AM
The intention is to print the current Activity where the workflow actually is sitting.
This is for Normal Change Request table >> wf_history >> wf_context>> >> id (column)
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var t1 = '0000-00-00 00:00:00';
var t2;
var act;
var gr = new GlideRecord('wf_history');
gr.addQuery('context.id', current.number.sys_id); //<====== There is something wrong with this line I suppose, as it is not pulling in the current Change Request record
gr.query();
while(gr.next()){
t2 = gr.started;
if (t1 < t2){ //check the most recent wf activity
t1 = t2;
act = gr.activity.name;
}
}
template.print(act + ' ' + t1 + ' ' + t2 + '' + current.sys_id);
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 11:05 AM
From what I can see, from the change record, your running activity is 3 steps away: the change record has an associated wf_context (this is the running workflow), then from that you can find the wf_executing (this is the running activity - be careful here because you could potentially have multiple activities running at the same time), and then from that you get wf_activity (the activity in the workflow definition, which is I believe what you want the name of).
If I was to try and get the activity name, then I would run it like this:
var name = '';
var wfc = new GlideRecord('wf_context');
wfc.addQuery('id',current.sys_id);
wfc.query();
if(wfc.next()){
var ex = new GlideRecord('wf_executing');
ex.addQuery('context',wfc.sys_id);
ex.query();
if(ex.next()){
var ac = new GlideRecord('wf_activity');
ac.addQuery('sys_id',ex.activity);
ac.query();
if(ac.next()){
name = ac.name;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 11:05 AM
From what I can see, from the change record, your running activity is 3 steps away: the change record has an associated wf_context (this is the running workflow), then from that you can find the wf_executing (this is the running activity - be careful here because you could potentially have multiple activities running at the same time), and then from that you get wf_activity (the activity in the workflow definition, which is I believe what you want the name of).
If I was to try and get the activity name, then I would run it like this:
var name = '';
var wfc = new GlideRecord('wf_context');
wfc.addQuery('id',current.sys_id);
wfc.query();
if(wfc.next()){
var ex = new GlideRecord('wf_executing');
ex.addQuery('context',wfc.sys_id);
ex.query();
if(ex.next()){
var ac = new GlideRecord('wf_activity');
ac.addQuery('sys_id',ex.activity);
ac.query();
if(ac.next()){
name = ac.name;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 02:05 PM
Totally missed the 'wf_context' table.
Thanks so much for the reply Kristen the answer was bang on target!
For someone looking into similar issue, I ended up with something like:
var name = '';
var wfc = new GlideRecord('wf_context');
wfc.addQuery('id',current.sys_id);
wfc.query();
if(wfc.next()){
var ex = new GlideRecord('wf_executing');
ex.addQuery('context',wfc.sys_id);
ex.query();
if (ex.nect()){
name = ex.activity.name;
}
}
template.print(name);