Previous Value in Mail Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2013 05:36 AM
Hello,
Is it possible to output a previous field value in a mail script? Something like this:
<mail_script>
var pdd = previous.due_date.getDisplayValue();
template.print('previous due ' + pdd);
</mail_script>
Thanks!
Mark Didrikson
- Labels:
-
Analytics and Reports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2013 09:08 AM
This code is mostly credited to Service-Now Guru (http://www.servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/)
Load your changed fields up in an array into the parm2 through the table BR after update such as:
if (current.operation() == 'update'){
//Collect all changed fields
if (typeof GlideScriptRecordUtil != 'undefined')
var gru = GlideScriptRecordUtil.get(current);
else
var gru = Packages.com.glide.script.GlideRecordUtil.get(current);
var fields = gru.getChangedFieldNames(); //Get changed fields with database names
//Convert to JavaScript Array
gs.include('j2js');
fields = j2js(fields);
//Make sure to remove the useless variable changes.
fields = String(fields).replace(/variables,/g, "").replace(/,variables/g, "")
//filter out the addtl comment changes, they have their own email.
if(fields != 'comments' && fields != '')
gs.eventQueue('group.notify.update', current, itemSysID, fields);
}
then in your email you can use:
<mail_script>
//Process the changed fields
var fields = event.parm2.split(',');
for(x in fields){
//Get the field label, value, and type
var field = fields[x];
var fieldLabel = eval('current.' + field + '.getLabel()');
var fieldVal = eval('current.' + field+ '.getDisplayValue()');
var fieldType = eval('current.' + field + '.getED().getType()');
if(fieldType == -1){
//Print out last journal entry for journal fields
template.print('<b>Notes:</b> ' + eval('current.' + field + '.getJournalEntry(1)'));
}
else{
template.print('<b>' + fieldLabel + ':</b> ' + fieldVal + '\n');
}
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2013 10:43 AM
Hi,
I have similar kinda requirement. Actually i have a scheduled workflow where i'll collect all the requested items and provide summary of it including last changed service catalog variable value. So, instead of passing 'current', is there anyway that i can pass my requested item and acheive this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2013 10:48 AM
Thanks for sharing the modified script @dressman.
I did notice that on the email notification, we get two emails, one includes the updated/change fields, and the other is empty.
Both are trigger from the same email notification.
Any ideas why that may be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2013 11:06 AM
The reason you could be getting the duplicates is that any sla's you have running will later update the sla_due field which will kick off the event again. I forgot to mention I have a condition on the business rule '!current.sla_due.changes()' that will prevent an event from being created if it is due to this.