Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Condition for 60 day date validation

miro2
Mega Sage

Hi,

I have to create a condition to meet the below requirement:
Date of today is greater than Date of field 'Sent for Approval' + 60 days. The Date of field 'Sent for Approval' is a variable and I was able to add its value in the Dashboard using database view. I want to check which condition will be better: 

javascript:gs.daysAgoStart(60)

or '60@days@ago'?

 

The value field is the date of the field 'Sent for Approval'

miro2_0-1769771597677.pngor

miro2_1-1769771616676.png

 

 

 

2 ACCEPTED SOLUTIONS

Hi @miro2 

That’s a challenge. You need to store this in a proper date format first; then you can compare it. Otherwise, there’s no easy or direct way to do it. A date can be compared to another date, but a date versus a string cannot.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

@miro2 

that's not going to work.

That value holds string and you can't compare it with another string which holds the filter.

 

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

View solution in original post

17 REPLIES 17

@miro2 

that's not going to work.

That value holds string and you can't compare it with another string which holds the filter.

 

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

@miro2 

you can handle it like this

1) create classless client callable script include

2) call that in filter condition of data visualization

Sys Id [IS ONE OF] javascript: getMyRecords()

3) in that function form your query for State = Work In Progress and use GlideRecord on database view

-> then while you iterate grab the value field and store in GlideDate

-> compare it against today

-> if it satisfies then push that database view record sysId in array

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar 
It seems like this solution won’t work. I can’t call a script include function in the filter condition of a data visualization because the data source is a database view. It might work for a regular table, but I don’t see an option to use Database view sys ID.

The sys_id of the database view is a unique identifier, not exactly a sys_id. Something similar like this "__ENC__MDZjMDgzNzRkYmQwNDAxMGY3Nzc1MjZhZGM5NjE5ZGU". That will be the sys_id for the database view

Database view

miro2_1-1769784950718.png

@miro2 

you can push HR Case sysId in array and then in database view use something like this

hr -> prefix for HR Payroll database view table

hr_sys_id [IS ONE OF] javascript: getRecords()

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

vaishali231
Kilo Sage

Hey @miro2 

To find records where Sent for Approval is older than 60 days, use:

60@days@ago is recommended for reports and dashboards because it is simpler, easier to read, and better optimized.

javascript:gs.daysAgoStart(60) should only be used when you specifically need script-based date logic.

*************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.

Regards
Vaishali Singh