Glide record using gs.daysAgo and UTC time

catho
Tera Expert

I need to trigger a reminder email on 7 days to users who have had a survey created, but not answered it.

I have:

1) created an event for this

2) created an email notification (with the unique survey link for the user) triggered by the event

3) created a scheduled job - to identify the records and fire the event.

 

I have created a heap of surveys in our DEV instance, and updated sys_created_on  to have records on a range of days so I can validate the script.

 

I have been using a background script to identify the records that will trigger notification - and they seem to be out by 10 hours (we are in UTC).

 

Script:

var gr = new GlideRecord('asmt_assessment_instance');gr.query();


while (gr.next()) {

 

if ((gr.state == 'ready') && (gr.sys_created_on <= gs.daysAgo(6)) && (gr.sys_created_on >= gs.daysAgo(7))) {

 

gs.print (gr.number + " " + gr.sys_created_on);

}

 

}

 

Records found:

*** Script: SURVEY0010835 2019-06-14 04:23:43 
*** Script: SURVEY0010821 2019-06-14 20:23:43
*** Script: SURVEY0010822 2019-06-14 10:23:43
*** Script: SURVEY0010826 2019-06-14 22:23:43
*** Script: SURVEY0010817 2019-06-14 22:25:16

My issue is that this is not the actual dates that they were created >> see below
Background Script                    - SN when viewing survey
SURVEY0010835 2019-06-14 04:23:43 - 14-06-2019 14:23:43
SURVEY0010821 2019-06-14 20:23:43 - 15-06-2019 06:23:43
SURVEY0010822 2019-06-14 10:23:43 - 14-06-2019 20:23:43
SURVEY0010826 2019-06-14 22:23:43 - 15-06-2019 08:23:43
SURVEY0010817 2019-06-14 22:25:16 - 15-06-2019 08:25:16

Is there anything I'm missing to easily identify items from 7 days ago? I have seen scripts a lot more complicating using date & time functions ..... I was hoping to do it in a simple way if possible as I'm not super strong at scripting.

 

 

1 ACCEPTED SOLUTION

Example using Incident - email Assigned to user until resolution every 7 days


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

6 REPLIES 6

find_real_file.png


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

catho
Tera Expert

The only issue I see with this is that the email notification we need to send has a fair bit of coding around it, and is in the notifications area.

 

I think when you choose: "send email" - you can generate an email - in rich text format - not html?

 

I guess I could look at a custom action to trigger the event though.

 

You definitely have me on the right track now thanks!