Connect Chat and Worknote Notifications

Callum Ridley1
Tera Guru

For some, like myself, worknotes in the system are more useful if they create notifications to ITIL users when tney are added. With this in mind, using Connect Chat can become problematic. Every time a chat message is added against a record in ServiceNow that has worknote notifications, an email is generated and sent. For lengthy chat sessions this can generate a large volume of unwanted email notifications.

To combat this we need to stop an email notification from being sent if the origin of the worknote is from a chat message. after a bit of digging around the base system tables I came up with the following script include that provides a way of determining the origin of a worknote or comment on a record.

Type: Script Include

Name: chatChecker

var chatChecker = Class.create();

chatChecker.prototype = {

        initialize: function() {

        },

        check: function (tableName, recSysID){

                  //first we check if there is even a conversation associated to this incident...

                  var liveGroupProf = new GlideRecord('live_group_profile');

                  liveGroupProf.addQuery('table', tableName);

                  liveGroupProf.addQuery('document', recSysID);

                  liveGroupProf.query();

                  if (!liveGroupProf.hasNext()) {

                            //no profile found; then just send as normal.

                            return true;

                  }else{

                            // Found a profile, now check to see if there is a new chat message associated with it

                            liveGroupProf.next();

                            var liveFeedMessage = new GlideRecord('live_message');

                            liveFeedMessage.addQuery('group',liveGroupProf.sys_id);

                            liveFeedMessage.orderByDesc('sys_created_on');

                            liveFeedMessage.query();

                            liveFeedMessage.next();

                            if(liveFeedMessage.chat_message == true){

                                      return false;

                            }else{

                                      return true;

                            }

                  }

        },

        type: 'chatChecker'

};

Then on the notifications you'd like to stop when the trigger is a chat message, you can add the following code into the "Advanced Condition" field.

var chatChecker = new chatChecker();

answer = chatChecker.check(current.getTableName(), current.sys_id);

I hope this helps someone else!

12 REPLIES 12

hrng
Giga Expert

Wouldn't this result in no notifications ever firing on that task ever again?



You'd have to add a filter on sys_created_on to be in the last few minutes or something, right?


HI Dave,



Lines 23 - 27 deals with this. Once a live profile exists every single comment or work note update is added to it. If the update source is from a chat window then the true/false value "chat_message" is set to true. On line 19 we add a GlideRecord query to return the results in order of newest to oldest as we just want the most recently created record. This most recently created record is selected on line 21 using the GlideRecord method "next()".



I hope that makes sense.



Callum


Makes perfect sense, thanks Callum!


hugogomes
Giga Expert

I have tried this code and it works, but the problem is that it is excluding all the additional comments. If I put an entry as additional comment, the notification is not being sent.



I can see that it is querying using the sys id of the message but it is not working for some reason.



Anyone had the same issue?