My script is not working

suuriyas
Tera Contributor

HI Community,

 

I have a requirement to generate a request when the records in sys certificate table has no valid from and no expires and with tag as valid certificate only for these records the request needs to be generated after 11 months from the created date.

 

so i have written a scheduled job for this and i tried testing it in background script but it is not working

Please let me know what is wrong in my script 

Note ; while testing i commented out this line (createdDateTime.addMonths(11);)

and created one new record in certificate table today and tested but it did not work

My script :

(function(){
    var today = new GlideDateTime();
    var certificates = new GlideRecord('sys_certificate');

    certificates.addNullQuery('valid_from');
    certificates.addNullQuery('expires');
    certificates.query('sys_tags','valid certificate');
    certificates.query();

while (certificates.next()){
    var createdDate = certificates.getValue('sys_created_on');
    var createdDateTime = new GlideDateTime(createdDate);

    createdDateTime.addMonths(11);

    if (createdDateTime.getDate() == today.getDate()&& createdDateTime.getMonth() == today.getMonth()&& createdDateTime.getYear() == today.getYear())
    {
        var cart = new Cart();
        var item = cart.addItem ('0b6fa369ebcc9610b2bff25e1bd0cd63');
        cart.setVariable(item, 'requested_for','e78e613febf41650b2bff25e1bd0cda3');
        cart.setVariable(item, 'username' , 'extsridhsu');
        cart.setVariable(item, 'short_description', 'Certificate expiration request for ' + certificates.name);
        cart.setVariable(item, 'business_justification', 'Certificate is about to expiry in next 30 days');
        var rc = cart.placeOrder();




    }
}

})();


15 REPLIES 15

@suuriyas 

Glad to know that my comment regarding checking query for sys_tags helped you.

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