- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 08:20 AM
Hello everyone,
I am trying to create an email notification that notifies the submitter of an enhancement when fields change on the form, and specifically which field was changed. Our current implementation is set to trigger on form update and sends the notification with a collection of a few pertinent fields on the enhancement form, but it doesn't specify which field was changed ending up with the user either having no idea what was updated (for those that don't keep a super close track of their items) or them having to scour the fields to find what was changed (I am aware of the history functionality, but in many cases these are non-IT people chances are they don't want to learn about the history functionality).
I had initially thought that we could create a single email notification per each field that we want to notify the user if there is changes on (which is a bit arduos to potentially create 10+ notifications), but it was pointed out that this would also send one email per field update so if an analyst completed several updates at once the business client would be blasted with a slew of notifications.
I've taken a look at the wiki and community and I don't think someone has asked this question before, so I'm hoping someone out there has a suggestion!
Thanks so much in advance,
Matt Langton
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 09:21 AM
I have always done this in a kind of brute force way. For example:
var automatic_comment = '';
if (current.description.changes()) {
automatic_comment += 'Revised description. ';
changes = true;
}
if (current.short_description.changes()) {
automatic_comment += 'Short description updated. ';
changes = true;
}
if (current.u_comments.changes()) {
automatic_comment += 'Comment added.';
changes = true;
}
if (current.u_tools_product.changes()) {
automatic_comment += 'Assigned Product: ' + current.u_tools_product.u_name + '. ';
changes = true;
}
if (current.u_tools_subproduct.changes()) {
automatic_comment += 'Assigned Subproduct: ' + current.u_tools_subproduct.u_name + '. ';
changes = true;
}
if (current.u_affected_release.changes()) {
automatic_comment += 'Identified affected release: ' + current.u_affected_release.u_name + '. ';
changes = true;
}
if (current.u_type.changes()) {
automatic_comment += 'Assigned issue type. ';
changes = true;
}
if (current.u_issue_priority.changes()) {
automatic_comment += 'Assigned priority. ';
changes = true;
}
if (current.assigned_to.changes()) {
automatic_comment += 'Changed owner to ' + current.assigned_to.name + '. ';
changes = true;
}
if (current.u_status.changes()) {
automatic_comment += 'Changed status to ' + current.u_status + '. ';
changes = true;
}
if (current.u_targeted_release.changes()) {
automatic_comment += 'Changed target release to ' + current.u_targeted_release.u_name + '. ';
changes = true;
}
if (current.u_scheduled_release.changes()) {
automatic_comment += 'Changed release schedule. ';
changes = true;
}
if (current.u_released.changes()) {
automatic_comment += 'Released on ' + current.u_released + '. ';
changes = true;
}
if (current.u_brief_status.changes()) {
automatic_comment += current.u_brief_status + ' ';
changes = true;
}
if (current.closed_at.changes()) {
automatic_comment += 'Changed close date. ';
changes = true;
}
if (current.u_admin_task.changes()) {
automatic_comment += 'Changed administrative task. ';
changes = true;
}
etc.,
then later on, while building the email message:
if (automatic_comment != '') {
email_body += '<tr><td align="center" colspan = >' + automatic_comment + '</td></tr>';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 09:21 AM
I have always done this in a kind of brute force way. For example:
var automatic_comment = '';
if (current.description.changes()) {
automatic_comment += 'Revised description. ';
changes = true;
}
if (current.short_description.changes()) {
automatic_comment += 'Short description updated. ';
changes = true;
}
if (current.u_comments.changes()) {
automatic_comment += 'Comment added.';
changes = true;
}
if (current.u_tools_product.changes()) {
automatic_comment += 'Assigned Product: ' + current.u_tools_product.u_name + '. ';
changes = true;
}
if (current.u_tools_subproduct.changes()) {
automatic_comment += 'Assigned Subproduct: ' + current.u_tools_subproduct.u_name + '. ';
changes = true;
}
if (current.u_affected_release.changes()) {
automatic_comment += 'Identified affected release: ' + current.u_affected_release.u_name + '. ';
changes = true;
}
if (current.u_type.changes()) {
automatic_comment += 'Assigned issue type. ';
changes = true;
}
if (current.u_issue_priority.changes()) {
automatic_comment += 'Assigned priority. ';
changes = true;
}
if (current.assigned_to.changes()) {
automatic_comment += 'Changed owner to ' + current.assigned_to.name + '. ';
changes = true;
}
if (current.u_status.changes()) {
automatic_comment += 'Changed status to ' + current.u_status + '. ';
changes = true;
}
if (current.u_targeted_release.changes()) {
automatic_comment += 'Changed target release to ' + current.u_targeted_release.u_name + '. ';
changes = true;
}
if (current.u_scheduled_release.changes()) {
automatic_comment += 'Changed release schedule. ';
changes = true;
}
if (current.u_released.changes()) {
automatic_comment += 'Released on ' + current.u_released + '. ';
changes = true;
}
if (current.u_brief_status.changes()) {
automatic_comment += current.u_brief_status + ' ';
changes = true;
}
if (current.closed_at.changes()) {
automatic_comment += 'Changed close date. ';
changes = true;
}
if (current.u_admin_task.changes()) {
automatic_comment += 'Changed administrative task. ';
changes = true;
}
etc.,
then later on, while building the email message:
if (automatic_comment != '') {
email_body += '<tr><td align="center" colspan = >' + automatic_comment + '</td></tr>';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 11:03 AM
we can simplify the solution a bit by using Property to store the field names and then using the below script to get the change log.
var fld=gs.getProperty(<property to store field names>)
var fldArr=fld.split(',');
var automatic_comment = '';
for(var i=0;i<fldArr.length;i++)
{ var fldName=fldArr[i];
if (current[fldName].changes())
{
automatic_comment += fldName +" changed to "+ current[pro]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2014 09:44 AM
This routine is very similar to Nisheeth's in how it works (OK, it is a Business Rule), but I have added a check to ignore specific fields
I want a notification to go to the 3rd party if some fields change, but not for other fields (either due to the 3rd party does not need an update when these fields change, or the fields in question need a different SOAP Envelope [work_notes; comments])
function fieldschanged() {
var strNoCheck = 'number; sys_updated_by; sys_updated_on; opened_by; sys_created_by; sys_created_on; phase; u_approval_reset; closed_at; sys_mod_count; phase_state; u_total_time_worked; sys_class_name; stage; active; work_notes; comments; parent';
var fields = current.getFields();
for (var i=0; i < fields.size(); i++)
{
field = fields.get(i);
if (field.changes() && strNoCheck.toLowerCase().indexOf(field.getName().toLowerCase()) == -1)
{
gs.log('This field has changed : ' + field.getDisplayValue());
return true;
}
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2014 05:20 PM
We had a similar requirement from project managers who wanted to be notified when project tasks were updated and they wanted the notification to indicate the changes made to the task.
Our approach was to use a Business Rule to get a list of the fields that were changed and to pass that list into an event, and use the event to fire the notification. The notification is passed the list of modified fields in the event and steps through them to create the email.
We stole this approach without any shame or regret whatsoever from Mark Stanger (Crossfuze), who posted it in this article: Checking for Modified or Changed Fields in Script on the ServiceNow Guru website. The part about creating the email is a couple sections down, but the entire article is worth a read.