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

 

 

 

16 REPLIES 16

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  ||  9x 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