Its_Sagnic
Giga Guru

Hi @Community Alums

(function() {

    var today = new GlideDateTime(); 
    
    var gr = new GlideRecord('sn_grc_indicator');
    gr.addEncodedQuery('item.sys_class_name=sn_risk_risk^ORitemISEMPTY^category=Risk Indicator^passed=failed^u_failed_dateISNOTEMPTY');
    gr.query();

    while (gr.next()) {
        gs.info('Processing GRC Indicator: ' + gr.number);

        var failedDate = new GlideDateTime(gr.u_failed_date); // Captured Indicator failed date
        var duration = GlideDateTime.subtract(failedDate, today);
        var diffInDays = duration.getDayPart();
        
        gs.info('The diffInDays is: ' + diffInDays);
        
    }
})();

@Community Alums ,

I used a same kind of code in a Scheduled job to get the diffrence between start date and failed date in an Indicator.

So the code that I used is returning the day differnce between start and failed date. You may use the same code and modify it as per your use case.

(function() {

    var today = new GlideDateTime(); 
    
    var gr = new GlideRecord('sn_grc_indicator');
    gr.addEncodedQuery('item.sys_class_name=sn_risk_risk^ORitemISEMPTY^category=Risk Indicator^passed=failed^u_failed_dateISNOTEMPTY');
    gr.query();

    while (gr.next()) {
        gs.info('Processing GRC Indicator: ' + gr.number);

        var failedDate = new GlideDateTime(gr.u_failed_date); // captured the failed date from indicator
        var duration = GlideDateTime.subtract(failedDate, today);
        var diffInDays = duration.getDayPart();
        
        gs.info('The diffInDays is: ' + diffInDays);
        
    }
})();


Change the  " u_failed_date "  and put your end date field "u_access_last_verified" In place of it and you will get your desired Output.

If you find it helpful for you please mark it as helpful and accept the solution.

Regards,

Sagnic