How can i get previous stage value in Emails?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 02:07 AM
Hi Everyone,
I'm facing an issue, If anyone knows please guide me how to do that.
Briefly., We need previous Ritm stage value.We will send an email in the subject like Your Ritm stage changes from example open to waiting approval.
How can i get previous stage value in the email????
Regards,
Rakhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 02:16 AM
Hello,
As the notification is created after the record is saved to the database I can only see two options:
Trigger the notification with an event that holds the previous state as one of the parameters. In the notification, get the information from the parameter.
Create an email script that checks the sys_audit log for previous value on stage. This is perhaps the more resource heavy option, but lets you keep everything else about the notification and how it triggers intact.
For examples on scripts and event triggering you can look here:
https://community.servicenow.com/community?id=community_article&sys_id=054deee5dbd0dbc01dcaf3231f961912
With regards
Anton Vettefyr

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 02:32 AM
Hi Felladin,
Thanks for giving a valuable information regarding my issue.
But i started newly in servicenow. And i created a event and it should be fire when stage is changes by using of BR. And my doubt is like how will a write script in notification.
How to call the parameter into notification can you provide reference script for me that is very helpful for resolving this issue.
With regards
Rakhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 06:42 AM
Hello,
Did you check the link I sent? It should have guidance to both event triggers as well as email script.
With regards
Anton Vettefyr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 06:34 PM
I wrote this script to include all states and their state for the user. maybe it will help enhance your emails for a visual representation of the process
(function runMailScript(current, template, email, email_action, event) {
var req_item_id = current.sys_id;
var sc_req_item = new GlideRecord('sc_req_item');
sc_req_item.get(req_item_id);
var properties = {
'workflow_driven_show_approvers': gs.getProperty("glide.workflow.renderer.workflowdriven.show_approver"),
'linear_show_approvers': gs.getProperty("glide.workflow.renderer.linear.show_approver"),
'main_flow_show_approvers': gs.getProperty("glide.workflow.renderer.mainflow.show_approver")
};
var ref = sc_req_item.stage;
GlideController.putGlobal('sc_req_item', sc_req_item);
sc_req_item.putCurrent();
var renderer = RendererFactory.getRenderer(ref, sc_req_item.sys_id);
var api = new SNC.RendererAPI(renderer);
var renderstyle = renderer + "";
var worflow_id = sc_req_item.stage;
var choiceList;
if (renderer == 'Legacy' || renderer == "SCReqItemRenderer") {
if (ref.getProviderType() == 'PFStagesProvider') {
choiceList = ref.getStages();
} else {
var clGenerator = new GlideChoiceListGenerator('sc_req_item', 'stage');
clGenerator.none = false;
choiceList = clGenerator.get();
api.internationalizeChoices(choiceList);
var wfw;
if (sc_req_item.stage.hasAttribute('icons')) {
wfw = eval("var ans = new " + sc_req_item.stage.getAttribute('icons') + "('sc_req_item.stage'); ans;");
choiceList = wfw.process(choiceList);
} else {
wfw = new WorkflowIcons('sc_req_item.stage');
choiceList = wfw.process(choiceList);
}
}
var list = [];
if (!JSUtil.nil(choiceList)) {
for (var i = 0; i < choiceList.size(); i++) {
var choice = choiceList.get(i);
if (!JSUtil.nil(choice.getValue())) {
var temp = {};
temp.label = choice.getLabel();
temp.title = choice.getParameter('title') || choice.getLabel();
if (renderer == 'Legacy') {
temp.displayValue = temp.title + " (" + temp.label + ")";
} else {
temp.displayValue = temp.label;
}
temp.value = choice.getValue();
temp.id = choice.getId();
temp.selected = choice.getSelected();
var imgsrc = choice.image.split(' ');
imgsrc = imgsrc.length ? imgsrc[0] : imgsrc;
if (!imgsrc)
imgsrc = temp.selected ? 'icon-check-circle' : 'icon-empty-circle';
temp.image = imgsrc + '.png';
list.push(temp);
}
}
}
var datachoiceList = list;
} else if (renderer == "Linear" || renderer == "Main flow" || renderer == "Workflow-driven") {
if (renderer == "Linear" || renderer == "Workflow-driven")
choiceList = api.getAllWorkflowChoices(current, 'sc_req_item.stage');
else
choiceList = api.getParentWorkflowChoices(current, 'sc_req_item.stage');
var showApprovers = false;
if (renderer == "Linear")
showApprovers = properties.linear_show_approvers == "true";
else if (renderer == "Main flow")
showApprovers = properties.main_flow_show_approvers == "true";
else if (renderer == "Workflow-driven")
showApprovers = properties.workflow_driven_show_approvers == "true";
api.addIconsAndStatus(choiceList);
var list = [];
if (!JSUtil.nil(choiceList)) {
for (var j = 0; j < choiceList.size(); j++) {
var choice = choiceList.get(j);
var isVisible = true;
if (renderer == "Linear" && !api.getOption('showSkipped'))
if (choice.getParameter('state') + '' == 'skipped')
isVisible = false;
if (renderer == "Main flow" || renderer == "Workflow-driven") {
var isWorkFlow = SNC.WorkflowStageRenderer.isWorkflow('sc_req_item.stage');
isVisible = (isWorkFlow == 'false') || ((choice.getParameter('visible') + '') == 'true');
}
if (choice.value == '')
isVisible = false;
if (isVisible) {
var temp = {};
temp.label = choice.getLabel();
temp.value = choice.getValue();
temp.id = choice.getId();
temp.selected = choice.getSelected();
if (showApprovers) {
var approvers = choice.getParameter('approvers');
var approverArr = [];
for (var i = 0; i < approvers.size(); i++) {
var approver = approvers.get(i);
approverArr.push(approver.get('label'));
}
}
temp.approvers = approverArr;
temp.title = choice.getParameter('title') || choice.getLabel();
temp.displayValue = temp.title + " (" + temp.label + ")"
var imgsrc = choice.image.split(' ');
imgsrc = imgsrc.length ? imgsrc[0] : imgsrc;
if (!imgsrc)
imgsrc = temp.selected ? 'icon-check-circle' : 'icon-empty-circle';
temp.image = imgsrc + '.png';
list.push(temp);
}
}
}
var datachoiceList = list;
} else if (renderer == "SimpleProgressBar") {
choiceList = api.getParentWorkflowChoices(current, 'sc_req_item.stage');
var showValue = api.getOption('showValue') + '';
var increment = 100.00 / choiceList.getSize();
var percentComplete = 0;
var atEnd = true;
for (var i = 0; choiceList.getSize() > i; i++) {
percentComplete += increment;
if (choiceList.getChoice(i).getParameter('state') + '' === 'active') {
atEnd = false;
break;
}
}
data.increment = increment;
percentComplete = atEnd ? 100 : parseInt(percentComplete);
if (!JSUtil.nil(choiceList)) {
var list = [];
for (var j = 0; j < choiceList.size(); j++) {
var choice = choiceList.get(j);
var isVisible = true;
if (!api.getOption('showSkipped'))
if (choice.getParameter('state') + '' == 'skipped')
isVisible = false;
if (choice.value == '')
isVisible = false;
if (isVisible) {
var temp = {};
temp.label = choice.getLabel();
temp.value = choice.getValue();
temp.id = choice.getId();
temp.selected = choice.getSelected();
temp.title = choice.getParameter('title') || choice.getLabel();
var isVisible = true;
temp.isVisible = isVisible;
temp.displayValue = temp.label;
var imgsrc = 'progress_pctnotdone.gifx';
if (choice.getParameter('state') + '' != 'pending')
imgsrc = 'progress_pctdone.gifx';
temp.image = imgsrc;
list.push(temp);
}
}
}
var datachoiceList = list;
}
GlideController.removeGlobal('sc_req_item');
sc_req_item.popCurrent();
/*
*** Script: datachoiceList[i].title = PHR Data Access Managers Approval
*** Script: datachoiceList[i].displayValue = PHR Data Access Managers Approval (Completed)
*** Script: datachoiceList[i].image = icon-check-circle.png
*** Script: datachoiceList[i].label = Completed
*** Script: datachoiceList[i].value = phr_data_managers_approval
*** Script: datachoiceList[i].approvers = Huifang Pan (Requested),Huifang Pan (No Longer Required),Jennifer Riggs (Requested),Jennifer Riggs (Approved)
*/
//List Only of Stages with No Approval History
/*for (i = 0; i < datachoiceList.length; i++) {
template.print('<img title="' + datachoiceList[i].displayValue + '" class="nopadding" src="https://' + gs.getProperty('instance_name') + '.service-now.com/images/heisenberg_icons/stage_icons/' + datachoiceList[i].image + '" alt="' + datachoiceList[i].displayValue + '"/> '+datachoiceList[i].title + "<br>");
}*/
//List of Stages WITH Approval History
for (i = 0; i < datachoiceList.length; i++) {
if (datachoiceList[i].displayValue != 'Request Approved (Approved)') {
template.print('<div class="stage-on">');
template.print('<img title="' + datachoiceList[i].displayValue + '" class="nopadding" src="https://' + gs.getProperty('instance_name') + '.service-now.com/images/heisenberg_icons/stage_icons/' + datachoiceList[i].image + '" alt="' + datachoiceList[i].displayValue + '"/>');
if (datachoiceList[i].image == 'icon-arrow-right.png')
template.print('<span style="font-weight:bold;"> ' + datachoiceList[i].displayValue + '</span>');
if (datachoiceList[i].image != 'icon-arrow-right.png')
template.print('<span> ' + datachoiceList[i].displayValue + '</span>');
var stepapprovals = new GlideRecord('sysapproval_approver');
stepapprovals.addQuery('document_id', current.sys_id);
stepapprovals.addQuery('wf_activity.name', datachoiceList[i].title.toString());
stepapprovals.addQuery('state!=not_required');
stepapprovals.query();
if (stepapprovals.getRowCount() > 0) {
//var approverhoistory = datachoiceList[i].approvers.toString();
//approverhoistory = approverhoistory.split(',');
template.print('<small style="color: #6c757d!important;">');
//template.print('<br><span> Approvers</span>');
template.print('<ul style="list-style: none;">');
while (stepapprovals.next()) {
template.print('<li style="color: #6c757d!important;">' + stepapprovals.approver.getDisplayValue() + ' (' + stepapprovals.state.getDisplayValue() + ')</li>');
}
//for (a = 0; a < approverhoistory.length; a++) {
// if (!approverhoistory[a].endsWith('(No Longer Required)'))
// template.print('<li style="color: #6c757d!important;">' + approverhoistory[a] + '</li>');
//}
template.print('</ul>');
template.print('</small>');
}
template.print('</div>');
}
}
template.print('<p> </p>');
})(current, template, email, email_action, event);