4 days prior to Last day worked date field

TejashviT
Tera Contributor

Hi Community,

Good Day !

 I have to trigger notification based on the condition "4 days prior to Last day worked date field" . I tried multiple things in condition builder but nothing is working fine. It returning unexpected records.

Please guide me how can build this condition in condition builder and use to trigger notification.

I also have attach the screenshot for the condition builder , I am using .

Thanks in advance 🙂

7 REPLIES 7

Hello @TejashviT 

 

You will not be able to achieve that in the list view rather you need a script like:

 

var glideRecord = new GlideRecord('your_table');
var todayDate = new GlideDate();
glideRecord.query();

while (glideRecord.next()) {
var lastDayWorked = glideRecord.getValue('last_day_worked');
var calculatedDate = new GlideDate();
calculatedDate.setValue(lastDayWorked);
calculatedDate.addDays(-4);

if (calculatedDate.equals(todayDate)) {
gs.info("Record exactly 4 days before 'last_day_worked': " + glideRecord.getDisplayValue('column_name')); // print the column
}
}


Hope that helps!

shantanu_patel8
Mega Guru

Hi @TejashviT ,

 

The normal condition builder is not going to work for the purpose.

 

You will need to use script. You can use something like this as script:

 

var nowDate = new GlideDateTime();
nowDate.addDays(4);
var todayDate = nowDate.getDate();

var inc = new GlideRecord('incident');
inc.addQuery('sys_updated_on','>',todayDate+'00:00:00');
inc.addQuery('sys_updated_on','<',todayDate+'23:59:59');
inc.query();
while(inc.next())
gs.info(inc.getDisplayValue());
 
NOTE : you can replace "incident" with your own table name and "sys_updated_on" as the last working day field name.
 
The above query will give you all the relevant records with last working day falling on 4 days from today.
 

Please mark the answer helpful and correct if it resolves the issue. Happy scripting 🙂

 

-Shantanu

 

Ankur Bawiskar
Tera Patron
Tera Patron

@TejashviT 

you cannot achieve this using filter condition, you will need script for this

1) get the today's date

2) subtract 4 days

3) then compare that date against your date field value

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader