Requested Item Comment - comment.user displays as 'undefined'

athavichith
Kilo Sage

When a user post a comment on the requested item, it displays as 'undefined' in the notifications. 

9 REPLIES 9

Viraj Hudlikar
Giga Sage

Hello @athavichith 

 

Can you paste code or script logic used to showcase this over your notification?

 

Is this happening for specific user or for all user? Did you tried to test notification being used by passing another example.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

this is on the 'comment_left_request' notification script. Here is the script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */ event) {

    var width = 'width: 100%;';
    var fontSize = 'font-size: 16px;';
    var lineHeight = 'line-height: 24px;';
    var paddingTop = 'padding-top: 16px;';
    var marginBottom = 'margin-bottom: 16px;';
    var notificationUtil = new RequestNotificationUtil();
    var comment = notificationUtil.getComments(current.sys_id, 'sc_req_item');
    var salutation = notificationUtil.setGreetingsMessage(current, email_action);
    var portalSuffix = new sn_ex_emp_fd.FoundationNotificationUtil().getPortalSuffix();
    var uri = gs.getProperty('glide.servlet.uri') + portalSuffix +'?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id;
    var catalogItemJS = new sn_sc.CatItem(current.cat_item);
    var catItemDetails = catalogItemJS.getItemSummary(true);
    var desc = catItemDetails.name.toString();

    template.print('<div style="font-size: 24px; line-height: 36px; text-align: center; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid #DADDE2;">' + comment.user + ' added a comment to your request</div>');
    template.print('<div style="' + width + fontSize + lineHeight + '">'+ salutation + '</div>');
    template.print('<div style="' + width + fontSize + lineHeight + paddingTop + '">' + comment.user + ' left a comment on <span style="font-weight: 600;">' + current.number + ':</span></div>');
    template.print('<div style="' + width + fontSize + lineHeight + paddingTop + marginBottom + '"><span style="font-weight: 600;">"' + comment.val + '"</span></div>');
    notificationUtil.createNotificationPrimayAction(template, uri, 'View comments');
    template.print('<div style="font-size: 20px; line-height: 30px; font-weight: 600; margin-bottom: 16px;">About this request</div>');
    template.print('<div style="' + fontSize + lineHeight + '"><span>Request number: </span><span style="font-weight: 600;">' + current.number + '</span></div>');
    template.print('<div style="' + fontSize + lineHeight + ' margin-bottom: 16px;"><span>Short description: </span><span style="font-weight: 600;">' + desc + '</span></div>');

})(current, template, email, email_action, event);


This does happen for every users. Tried replacing comment.user to gs.getUser().getDisplayName() but it retrieved the display name of the 'System Admin' when tested. 

Hi @athavichith ,

If your notification script is in another scope, Try to add global prefix for script include as below


var notificationUtil = new global.RequestNotificationUtil();

 

I have created a fix script and try to call the RequestNotificationUtil() from scoped application and it returns the "undefined" in the error. Also, nothing was displayed on the log.

Pooja58_0-1739810379706.pngPooja58_1-1739810442848.png

 

 

Now when I tried to add global qualifier, I got below output. along with info message as below

Pooja58_2-1739810519279.png

Pooja58_3-1739810934081.png

 

NOTE: Impersonated Abel Tuter for adding comments. And it shows abel's name correctly in the log.

Please mark my answer as correct/helpful if this solves your question.

Best Regards,

Pooja

 

Hi @athavichith ,
Did you get a chance to check the above solution?
If it solves your query, Kindly mark as helpful!

Best Regards,

Pooja