For Visual task board (Private task) notification are triggering as undefined.

NagaNandini N
Tera Guru

Hi All,

 

Please help me on the visual task board (private task). Notifications are triggered as undefined when the additional comments are updated for the user only for private task updates. Please find the below code for reference.

 

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

    //Use the MentionNotes script include to retrieve the comment/work note left with the mention
    var notesFunction =new RTTMentionNotes();
    var mentionMessage = notesFunction.getRTTMentionNotes(current);
   
    email.setSubject("You have been mentioned in " + subjectText);
    template.print("<p style='color: #000000;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>");
    template.print("<p style='color: #000000;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>Here is your message:" + mentionMessage);

}
 
Function " RTTMentionNotes " code is below:
 
var RTTMentionNotes = Class.create();
RTTMentionNotes.prototype = {
    initialize: function() {},

    getRTTMentionNotes :function(live_notif){
        var returnText;
        var taskSysID;
        var type = live_notif.field_name; //comment or work_note
       
        //Populate taskSysID with the sys id of the task record that the mention was used in
        var taskGL = new GlideRecord('task');
        taskGL.addQuery('number', live_notif.title);
        taskGL.query();
        while(taskGL.next()){
            taskSysID = taskGL.getUniqueValue();
        }

        //Each comment/work note is saved as a record in the sys_journal_field table
        //Use the information we know to narrow our query and find the comment/work note that was used in our mention
        var journalEntry = new GlideRecord('sys_journal_field');
        journalEntry.addQuery('element_id', taskSysID); //sys id of the task the mention was made in
        journalEntry.addQuery('element', type); //comment or work_note
        journalEntry.addQuery('value', 'CONTAINS', '@'); //mentions will always contain the @ symbol

        // Order by created on date to get the latest record if more than one are returned
        journalEntry.orderByDesc('sys_created_on');

        // Return only latest comment
        journalEntry.setLimit(1);
       
        journalEntry.query();

        while(journalEntry.next()){
            returnText = journalEntry.value;
        }

        return returnText;
    },

    type: 'RTTMentionNotes'
};
2 ACCEPTED SOLUTIONS

Anil Lande
Kilo Patron

Hi,

Try updating your script include part like below:

   //I believe below GlideRecord is not is not required because document field stored the sys_id 
taskSysID = live_notif.document.toString();
//--------------------------------------------------------------------
//if you want to try your code then modify your code like below
//Populate taskSysID with the sys id of the task record that the mention was used in
        var taskGL = new GlideRecord('task');  
        //taskGL.addQuery('number', live_notif.title);
        taskGL.addQuery('sys_id', live_notif.document.toString());  // use sys_id based search to find correct record
        taskGL.query();
        while(taskGL.next()){
            taskSysID = taskGL.getUniqueValue();
        }
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

Yes, you can make use of GlideRecord script to get Task Record and number.

  //Populate taskSysID with the sys id of the task record that the mention was used in
var taskNumber;
        var taskGL = new GlideRecord('task');
        taskGL.addQuery('sys_id', live_notif.document);
        taskGL.query();
        if(taskGL.next()){
            taskSysID = taskGL.getUniqueValue();
taskNumber = taskGL.number;
// get any additional deatils 

        }

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

4 REPLIES 4

Anil Lande
Kilo Patron

Hi,

Try updating your script include part like below:

   //I believe below GlideRecord is not is not required because document field stored the sys_id 
taskSysID = live_notif.document.toString();
//--------------------------------------------------------------------
//if you want to try your code then modify your code like below
//Populate taskSysID with the sys id of the task record that the mention was used in
        var taskGL = new GlideRecord('task');  
        //taskGL.addQuery('number', live_notif.title);
        taskGL.addQuery('sys_id', live_notif.document.toString());  // use sys_id based search to find correct record
        taskGL.query();
        while(taskGL.next()){
            taskSysID = taskGL.getUniqueValue();
        }
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

 

Thank you for the update. It works. Is it possible to get the Private Task Number in the message? I have shared the screenshot like the SCTASK number I would like to have Private Task Number. 

 

 

 

Yes, you can make use of GlideRecord script to get Task Record and number.

  //Populate taskSysID with the sys id of the task record that the mention was used in
var taskNumber;
        var taskGL = new GlideRecord('task');
        taskGL.addQuery('sys_id', live_notif.document);
        taskGL.query();
        if(taskGL.next()){
            taskSysID = taskGL.getUniqueValue();
taskNumber = taskGL.number;
// get any additional deatils 

        }

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Glad to know your issue is resolved, could you please close this question by marking appropriate answers as correct solution?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande