Why does Email Script return Incident Number for incidents, but returns the Short Description for project tasks?

JR42
Giga Guru

Hello.  We have an Email Notification (Activity Stream @Mention Email) which uses an Email Script  (ng_activity_mention_body).

The same notification and email script are used for Incident records and Project Task records.

We have noticed that when this notification is sent for an Incident, the incident number is included in the Subject and Body.  However, when the notification is sent for a Project Task, the Short Description from the project task is used, in place of the number.

We would like the number to be displayed in the notification for project tasks, just as it is for Incidents.

 

Example notification for Incident:
Subject: You have been mentioned in INC0000001
Body: You have been mentioned by Joe in the Incident record INC0000001

Example notification for Project Task:
Subject: You have been mentioned in Customer Go-Live - Add blade servers
Body: You have been mentioned by Joe in the Project Task record Customer Go-Live - Add blade servers

 

Here is the Email script: ng_activity_mention_body

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

    var result = new ActivityMentionEmailValues().getEmailValues(current.table, current.document);
    if (result) {
        result = JSON.parse(result);
        email.setSubject(gs.getMessage("You have been mentioned in {0}", result.subjectText));
        template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>");
        template.print(gs.getMessage("You have been mentioned by {0} in", current.user_from.name));
        template.print("&nbsp;<a>" + result.linkText + "</a></p>");
    }

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

 

Can anyone point me in the right direction?

1 ACCEPTED SOLUTION

That is why I have asked you to verify Dictionary Override for short_description field. 

See the below images for reference;

As you can see that display value for Number field is set to true for vtb_task table.

find_real_file.png

 

But still I am getting short_description as display value in my script result.

Script:

find_real_file.png

Output:

find_real_file.png

Record:

find_real_file.png

 

This is because Override display value for short_description is set to true.

find_real_file.png

 

If I set it to false then I will get Number.

find_real_file.pngfind_real_file.png

By the way the image you have shared is not visible.

Hopefully, it will help you understand.

View solution in original post

9 REPLIES 9

JR42
Giga Guru

Thanks for the helpful replies!  I've reviewed all the table Dictionary entries and verified the Display value is set to false for every table column, in all of the tables below.

task
incident
pm_project
pm_project_task

Perhaps [incident] defaults to the Number and [pm_project_task] defaults to the Short Description, when all Table Column Display values are set to false?

The ServiceNow doc, 'Select a field as the table display value', indicates the following:

Reference fields look for the display value in the following order:

  1. A field with display=true in the system dictionary on the lowest sub-table for extended tables.
  2. A field with display=true in the system dictionary on the parent table.
  3. A field named name or u_name.
  4. The Created on field of the referenced record.

 

If the above were the case, I would expect to see the 'Created on' field being used, since display=false for everything and there is no 'name' or 'u_name' field on these records.

Did you check for Dictionary Override Override display value on the column which you are getting like short description

JR42
Giga Guru

I have set the Display value for Number in the pm_project_task table, but the notifications for project tasks still includes the Short Description.

 

That is why I have asked you to verify Dictionary Override for short_description field. 

See the below images for reference;

As you can see that display value for Number field is set to true for vtb_task table.

find_real_file.png

 

But still I am getting short_description as display value in my script result.

Script:

find_real_file.png

Output:

find_real_file.png

Record:

find_real_file.png

 

This is because Override display value for short_description is set to true.

find_real_file.png

 

If I set it to false then I will get Number.

find_real_file.pngfind_real_file.png

By the way the image you have shared is not visible.

Hopefully, it will help you understand.

Thank you very much Muhammad!  This helped a lot and has resolved the problem.