How can I include the Workflow Activity Name in notification email

rocktheboat
Giga Contributor

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);

1 ACCEPTED SOLUTION

kristenankeny
Tera Guru

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;


}


}


}


View solution in original post

2 REPLIES 2

kristenankeny
Tera Guru

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;


}


}


}


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);