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

Ankur Bawiskar
Tera Patron

@miro2 

the latest approach of using client callable script include worked fine for me

Please use that and let me know the feedback

💡 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

Hi @Ankur Bawiskar 
my script include works fine. I've checked it in a background script and it returns 1 record as expected. But when I try to call it in a condition, it doesn't work.

var GetMyRecordsScriptInclude = Class.create();
GetMyRecordsScriptInclude.prototype = {
    initialize: function() {},

    getMyRecords: function() {
        var resultArray = [];
        var gr = new GlideRecord('<my_database_view>');
        gr.addQuery('payroll_state', '18'); //WIP state
        gr.query();
        
        var today = new GlideDateTime();
        
        while (gr.next()) {
            var dateString = gr.getValue('qa_value');
            if (!dateString) {
                continue;
            }
            
            var recordDate = new GlideDateTime(dateString);
            recordDate.addDaysUTC(60);
            
            if (today.after(recordDate)) {
                resultArray.push(gr.getValue('payroll_sys_id'));
            }
        }
        return resultArray.join(',');
    },

    type: 'GetMyRecordsScriptInclude'
};

 

miro2_0-1769790542199.png

miro2_1-1769790650432.png



Database view-> the same result

miro2_2-1769790714933.png

 

 

Hi @Ankur Bawiskar 
regarding above solution about classless and client-callable script includes, I found that ServiceNow docs state that it can never be used client-side, even if the client callable option is selected.

Could you please share the steps you followed to fetch records using javascript&colon;getMyRecord() in a condition?
Could the fact that this SI/database view is in a scoped application be the reason why the condition returns null?

miro2_0-1769981168146.png

 


Thank you