- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 05:41 AM
Hi,
when creating a new incident ticket i i want the additional comments field to show in red to denote that this field will send an email to the caller.
I managed to work out that you can do this via field styles which works great, however i found a drawback, when my instance sends an email out using the Incident commented via ESS it shows the 3 most recent additional comments (which is fine, however the background of those comments is also red which i do not want, I want the background to always be white.
If i remove the field style on the tasks table > Additional Comments field then the notification is fine but then the field is no longer red when the incident form loads.
is there a way to achieve either of the following please?
1. can i reimplement the additional comments field style on the task table and somehow amend my email notification script to remove the red background? - here is my mail script - its very simply, it simply gets the last 3 comments as determined by the system property for Email Notifications.
(function runMailScript(current, template, email, email_action, event) {
template.print(gs.getMessage('${comments}'));
})(current, template, email, email_action, event);
OR 2. i dont touch the field style for the additional comments field, but is there a way upon loading the incident form that the additional comments field is red? - by default when a new form is loaded the field has no colour to it. i have also looked at the glide ui properties via sys_properties.list but none of that helps me.
I am hoping someone here can help me.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 08:22 AM
There is another way to handle this .You just need to update your Email script as below and works :
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var arr = [];
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', 'ed92e8d173d023002728660c4cf6a7bc');
gr.addQuery('name', 'incident');
gr.addQuery('element', 'comments');
gr.setLimit(3);
gr.query();
while (gr.next()) {
arr.push(gr.value.toString());
}
template.print(arr);
})(current, template, email, email_action, event);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 06:15 AM
Hi,
Please follow the steps to achieve your requirement:
1) I would suggest to make the Label of the field as Red which will show the users which you want. To do so please follow the below thread from Mark:
https://community.servicenow.com/community?id=community_question&sys_id=0b02ac07dbdac010feb1a851ca961914
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 06:26 AM
thank you for your reply, i will try it out, otherwise i found an alternative from the forums which is a script below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var comments = current.comments.getJournalEntry(1);
template.print('<p style="color: #343434; background-color: #ffffff; font-family: arial; font-size: 10pt">');
template.print(comments.substring(0,comments.indexOf("\n")));
template.print('<br>');
template.print(comments.substring(comments.indexOf("\n")+1));
template.print('</p>');
the above script will strip out the red colour if the field style is set as red however it is only designed to show the last comment, if i change the value to 3 in the .getJournalEntry() section the issue is that the comments are not separated by line breaks, its all one continuous line and looks very messy.
so my question is would you happen to know how to modify this script so it achieves the following:
1. shows the last 3 additional comments added into the incident record
2. formats them so they are separated by line breaks
if i leave the script as only showing 1 comment then it looks like this:
however if i change the above script ot show 3 comments then it looks like this:
if i can get the above script to put each comment on a separate line then this will i think achieve exactly what i want to achieve
thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 08:04 AM
Hi,
Ive managed to figure this out. just in case someone else on the forum has the same kind of issue as me, this is what i did:
1. i created my own notification email script called custom_incident_comments (call it whatever you want)
below is the script i added into it, its very basic as i dont need anything else (my Email layout takes care of fonts and formatting etc) the Email Layout is applied to a blank Email Template which is then applied to my Email Notifications.
(function runMailScript(current, template, email, email_action, event) {
template.print(gs.getMessage('${comments}'));
})(current, template, email, email_action, event);
please note the above will add into the outbound notification called Incident Commented via ESS the last 3 additional comments, this can be changed to whatever number you want via the Email Properties section and adjusting the number in the field called Number of journal entries (Additional comments, Work notes, etc.) included in email notifications (-1 means all).
2. i created a new field style for the incident table only (my mistake was that i was applying the field style to the task table)
go to field styles (under system ui) > new > and set up as follows:
- Table = Incident
- Field Name = Additional Comments
- Value = leave empty
- Style = background-color:#ffbeb2; (set this to whatever colour you want - you can add your own HTML colour here or go to Color Definition (under Reports > Administration) for a list of what ServiceNow has OOB
3. i then went to sys_properties.list and set the following glide UI settings (not sure these make any difference but i did it anyway for consistency) - maybe do steps 1 and 2 first to see what happens and then try step 3 if needed
glide.ui.activity.style.comments
- change value field to #ffbeb2
glide.ui.activity_stream.style.comments
- change value field to #ffbeb2
glide.ui.incident_activity.style.comments
- change value field to #ffbeb2
What does this achieve for me?
1. when i create a new incident record, the additional comments field is highlighted in UI14 Red Lighter colour
2. when i open an existing incident record, the additional comments field has a thin UI14 Red Lighter coloured bar on the left side of the field
3. when an email is sent to servicenow and an incident record is automatically created because of my inbound action, the additional comments field has a thin UI14 Red Lighter coloured bar on the left side of the field
4. (most important for me) when i add a comment into the additional comments field, and the caller receives the email notification, they will see the last 3 most recent comments in the incident record, this includes my most recent comment to the caller. the difference now is that the comments are not highlighted in UI14 Red Lighter colour and instead now have a white background as i want it.
the only reason i can see why the comments had a red background is because i was applying the additional comments field style to the Task table, which affects a lot more in the background including notifications. its best to simply target the table you want.
I hope this helps anyone else out as it certainly has done for me.
Thank you for your help and allowing me to figure this out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 08:22 AM
There is another way to handle this .You just need to update your Email script as below and works :
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var arr = [];
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', 'ed92e8d173d023002728660c4cf6a7bc');
gr.addQuery('name', 'incident');
gr.addQuery('element', 'comments');
gr.setLimit(3);
gr.query();
while (gr.next()) {
arr.push(gr.value.toString());
}
template.print(arr);
})(current, template, email, email_action, event);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke