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

Shishir Srivast
Mega Sage

Are you trying to gliderecord on the same table on which the notification would be running, can we use the current object? Not sure if you are trying to do get the gliderecord to fetch any specific value? we can use the current object to fetch the values.


I have tried just collecting the values directly, but the problem is you don't know whether the mention is coming from the work note or the comments.   So I'm trying to collect the "current.field_name" to collect the stored value which defines whether the mention was in a work note or comment, and then pass that value on to the string which will collect the value of the field "current.document.**field**.getDisplayValue()".



Both use the current document.


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));


}


Thank you very much!   This works perfectly.