How do you include the Short Description as part of the @mention Email?

zag
Tera Expert

I want the Short descritpion to follow email shown here. 

You have been mentioned by Root Mathew Xagoraris in CS0026575   "Short Description" 

 

 

this is my current code, any thoughts? The code below is in Notification Scripts.  Note I added current.short_description in the script below, everything but that works.  

 

var recordGR = new GlideRecord(current.table);

var field = current.field_name;

if(recordGR.get(current.document)) {

email.setSubject("You have been mentioned in " + recordGR.getDisplayValue());

template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>You have been mentioned by " + current.user_from.name + " in <a href='/" + recordGR.getRecordClassName() + current.short_description +".do?sys_id=" + recordGR.getUniqueValue() + "'>" + recordGR.getDisplayValue() + "</a></p>" + '<br>' + 'Comments: ' + current.document[field].getJournalEntry(1));

}

1 ACCEPTED SOLUTION

Matthew Smith
Kilo Sage

Hi zag

The current object is the live_notification table and this table does not have a short_description field, which is why current.short_description returns undefined. You need to use recordGR.short_description instead - the below seems to work for me:

var recordGR = new GlideRecord(current.table);
if(recordGR.get(current.document)) {
template.print("<span style='font-size: 10pt; font-family: verdana, geneva;'>You have been mentioned by " + current.user_from.name + "in <a href='/" + recordGR.getRecordClassName() + ".do?sys_id=" + recordGR.getUniqueValue() + "'>" + recordGR.getDisplayValue() + ' "' + recordGR.short_description + '"' + "</a></p>");
}

- Matt

View solution in original post

7 REPLIES 7

Jeff Currier
ServiceNow Employee
ServiceNow Employee

You are putting the short description within the URL link for the record.  You need to put the short description after the </a>  so something like:

template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>You have been mentioned by " + current.user_from.name + " in <a href='/" + recordGR.getRecordClassName() + ".do?sys_id=" + recordGR.getUniqueValue() + "'>" + linkText + "</a> : " + current.short_description + " </p>" + '<br>' + 'Comments: ' + current.document[field].getJournalEntry(1));

zag
Tera Expert

Hi Jeff, 

 

thanks for the insight!   The + "'>" + linkText  part of the code seems to  remove the all the text . I took that out but now I get  undefined  any thoughts as to why?   

 

You have been mentioned by Root Mathew Xagoraris in CS0026575 : undefined


Comments: 2019-12-31 11:35:28 EST - Root Mathew Xagoraris (Work notes (Internal)) @Root Mathew Xagoraris test 4

If you would like to stop receiving these emails you can disable "Activity Stream @Mention Email" in your Notification Preferences or Unsubscribe.

Jeff Currier
ServiceNow Employee
ServiceNow Employee

Maybe show me your full script.  The LinkText is the CS0026575.  If you click CS0026575 does it take you to the correct case?  if so, then the URL is working too and just the short description is not defined correctly.

Below is my script, which I think it 100% out of the box, just for reference.  Looking at this closer (without testing, sorry), I think you may need recordGR.get(current.short_description)

var recordGR = new GlideRecord(current.table);
if(recordGR.get(current.document)) {
var displayValue = recordGR.getDisplayValue();
var subjectText = displayValue
? displayValue
: "a record discussion";
var tableDisplay = recordGR.getClassDisplayValue();
var linkText = displayValue
? "the " + tableDisplay + " record " + displayValue
: "this " + tableDisplay + " record ";

email.setSubject("You have been mentioned in " + subjectText);
template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>You have been mentioned by " + current.user_from.name + " in <a href='/" + recordGR.getRecordClassName() + ".do?sys_id=" + recordGR.getUniqueValue() + "'>" + linkText + "</a></p>");
}

Here is the whole code with the Get Short Description highlighted. 

 

var recordGR = new GlideRecord(current.table);

var field = current.field_name;


if(recordGR.get(current.document)) {

email.setSubject("You have been mentioned in " + recordGR.getDisplayValue());

template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>You have been mentioned by " + current.user_from.name + " in <a href='/" + recordGR.getRecordClassName() + ".do?sys_id=" + recordGR.getUniqueValue() + "'>" + recordGR.getDisplayValue() + "</a> : "+recordGR.get(current.short_description) + "</a></p>" + '<br>' + 'Comments: ' + current.document[field].getJournalEntry(1));

}