Notification email System user show as undefined

dustinjones
Tera Expert

Hello,

 

I have a flow that updates the RITM with an additional comment. The ticket itself show the comment being made by SYSTEM but the notification email show the comment being made by UNDEFINED. Any thoughts?

 

Thanks

1 ACCEPTED SOLUTION

AnnMarieC
Tera Guru

Hi @dustinjones - I ran into the same issue. The user is getting set in the RequestNotificationUtilSNC script include. However SN provides the RequestNotificationUtil script include to write override functions if needed. So I copied the getComments function and modified where it sets the user. We just needed to replace it with Service Desk just so it didn't say undefined. So I updated the last section to the following:

 

if (!byUserName) {
   var userRec = new GlideRecord('sys_user');
   userRec.addQuery('user_name', journalRec.sys_created_by);
   userRec.setLimit(1);
   userRec.query();
   if (userRec.next()) {
      comment.user = userRec.name;
   } else if(journalRec.sys_created_by == 'system'){
      comment.user = "Service Desk"; //Replace this with the name you want to use
   }
}

 

 

View solution in original post

8 REPLIES 8

dustinjones
Tera Expert

Any thoughts on this?

AnnMarieC
Tera Guru

Hi @dustinjones - I ran into the same issue. The user is getting set in the RequestNotificationUtilSNC script include. However SN provides the RequestNotificationUtil script include to write override functions if needed. So I copied the getComments function and modified where it sets the user. We just needed to replace it with Service Desk just so it didn't say undefined. So I updated the last section to the following:

 

if (!byUserName) {
   var userRec = new GlideRecord('sys_user');
   userRec.addQuery('user_name', journalRec.sys_created_by);
   userRec.setLimit(1);
   userRec.query();
   if (userRec.next()) {
      comment.user = userRec.name;
   } else if(journalRec.sys_created_by == 'system'){
      comment.user = "Service Desk"; //Replace this with the name you want to use
   }
}

 

 

Found another issue in that same script, so if you are overriding might as well fix it too.  Line 193 has:

 

 

  journalRec.addQuery('elements', 'comments');

 

 by the field name is element. So correcting that line to:

 

  journalRec.addQuery('element', 'comments');

 

Should fix any inconsistencies with comments displayed.

Hey, thank you for this. This totally makes sense. I have tried to fix it tho and I keep breaking my notifications all together. Dev is not my strength. Where do I insert the code to make this work? I have been adding your above code to the RequestNotificationUtil script include but all the text in the notifcation breaks when I do. Below is what my current default one looks like.

 

var RequestNotificationUtil = Class.create();
RequestNotificationUtil.prototype = Object.extendsObject(RequestNotificationUtilSNC, {
    initialize: function() {
        RequestNotificationUtilSNC.prototype.initialize.apply(this, arguments);
    },

    type: 'RequestNotificationUtil'
});