E-Mail Script to display custom field(variable)

Arnab22
Giga Expert

Hi,

I need to display a custom variable defined in sc_request table for my SLA notification. The custom variable is u_service_category. Can you give me an example how this can be accomplished? I am new to Service Now and any help will be greatly appreciated.

 

Thanks,

 

1 ACCEPTED SOLUTION

Hi Arnab,

I logged into your instance and took a look around, I changed a few things and all of those updates are captured in the update set named "Test request sla" so it is easier for you to see what was changed, essentially.

1) There was not an SLA definition in the developer instance so I created one for the Request table.

2) I added "SLA" related list to the request form so I can see if SLA task is created.

3) I made some changes to the fields in the notification to get the correct values, I did not make any changes to the mail script you have in there, it printed out the correct value already without any changes needed.

Please take a look at these two emails, do they have all the information you needed? https://dev63739.service-now.com/sys_email_list.do?sysparm_query=sys_created_onONToday%40javascript%3Ags.beginningOfToday()%40javascript%3Ags.endOfToday()%5Esubject%3DSLA%20WARNING

Let me know if you have any questions 🙂

Thanks,

Phuong

View solution in original post

18 REPLIES 18

I see what you are trying to do. Can you tell me if the event being triggered (sla.warning.req) has the sys_id of the request in parameter 1 or 2? or if you pass the request over as the glide record? if you can show me how you triggered the event, I can help you better. It is a custom event right since i dont see it in my dev instance?

Hi,

I have attached a screenshot. The Warning and Breach Events are getting triggered and I am receiving the e-mail. The issue is when I receive the email, the Service_category field is blank.

find_real_file.png

So in your mail script, does current.task.u_service_category give you any value at all?

try printing out event.parm1 and event.parm2 in your mail script and see what you get.

Hi Phuong,

 

I see a message Service Category undefined. The Category Field (u_service_category) is not in the task_table and that is the source of my problem. I am not sure what additional references are needed to make this work. I compared the Incident Table and sc_request table and it is the same.

find_real_file.png

find_real_file.png

Hi Arnab,
 
Usually the flow goes like this:
1) You go the SLA definition to create a definition for a table (sc_request), in that definition, you determine when the SLA will be applied against that specific request.
2) When the condition matches, the system will create a record in the task_sla table that has a referenced field named "task" that links to the request. You can go the list of records in table by typing in the filter navigator "task_sla.list" and hit enter.
3) The workflow is triggered as well when the record is created in the task_sla table, this is when the time starting to count down, when it gets below a certain threshold, the workflow fire an event, in this case the "sla.warning.req" even (unless this is a custom event).
4) In that event, there should be a few parameters, usually the "current" glide record object (the task_sla record), parm1 contains the sys_id of the request, etc...
5) In your mail script, you have access to the "event" object, as well as the "current" object which is the "task_sla record. 
6) You should be able to dot walk to your custom field by current.task.u_service_category (you are practically dot-walking to the sc_request table, make sure that field has a value).
7) OR, if the event's parm1 contains the sys_id of the request, you can do a glide record query using that sys_id (event.parm1) to get the request object, then do what you need to do.
I don't suspect you can grant me access to your instance since it does not look like it is a Personal Developer Instance that you are working on.
 
Thanks,
Phuong