Pass a variable into the identifier string

David Morden
Mega Expert

Does anyone here know how to pass a variable into an identifier string in a script?

I'm trying to update the ng_activity_mention_body email script to include the work note or comment where the person was mentioned.   However, I can't seem to find out how to add a variable into the identifier string to get only the work note or comment which generated the mention notification.   Here is what I have so far, and please notice the variable is "field" and the identifier is at the end of the "template.print".

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></p>" + "<br></br>" + "Comments: " + current.document.field.getDisplayValue());

}

1 ACCEPTED SOLUTION

David,



Well, firstly you need to be using bracket notation in this particular case, I believe (see Property accessors - JavaScript | MDN ).



Also, getting the display value of journaled fields will return all the previous entries, I would use .getJournalEntry(n). In the example below I used "1" to get only the most recent entry.



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></p>" + '<br><br>' + 'Comments: ' + current.document[field].getJournalEntry(1));


}


View solution in original post

6 REPLIES 6

Hi dhasselquist,

 

I just wanted to display only the Text mentioned in the worknotes. So I had used the journal entry of worknotes in the  mail script "ng_activity_mention_body"  

script :


 if (current.field_name == "work_notes") {

template.print(recordGR.work_notes.getJournalEntry(1) + "<br />");

 }

 

and got the below result.

find_real_file.png

But here I tried of splitting the content of worknotes through the code in ng_activity_mention_body :

var work_notes = recordGR.work_notes.getJournalEntry(1);

var regex= new RegExp('\n'); // searching for the first line break
var work_notes2=work_notes;
var i = work_notes.search(regex);
if (i>0)
{
// taking everything after the first line break, he-he.
work_notes2 = work_notes.substring(i+2, work_notes.length);

template.print("COMMENTS: " + "</br/>" + work_notes2 + "<br />");

and result is:

find_real_file.png

So here I dont want to display the user name, but I am unable to find how to not get this @user and split the worknotes and get only the text.

Would be helpful if  this gets answered.

Thanks in advance.

Divya.