how can i send a notification email if the warranty is about to expire

S_matar
Tera Expert

Dears , 

Can some one assist on how to create a notification one month before the warranty expiration date for the assets  . 

find_real_file.png

1 ACCEPTED SOLUTION

S_matar
Tera Expert

this code worked perfectly fine for 30 days i generated 9/2/2019 it gave me 9/2/2020 . 

 

var policy = new GlideRecord('cmdb_ci');

var today = gs.nowDateTime();

var query = '';// modify your query accordingly

policy.addEncodedQuery(query);

policy.query();

//gs.log(policy);

while (policy.next()){


var total = gs.dateDiff(today,policy.getElement('warranty_expiration'), true);
//gs.log('Today: ' + today);
//gs.log('Warranty Expiration: ' + policy.getElement('warranty_expiration'));
//gs.log('Date Difference: ' + gs.dateDiff(today,policy.getElement('warranty_expiration'), true));

//gs.log('Total : ' + total);

var diff = Math.floor(total/86400);

//gs.log('Diff : ' + diff);

var no =policy.number;

//gs.log('No: ' + no);

var own = policy.owner.getDisplayValue();

//gs.log('Own : ' + own);

if (diff == 30 ){
//gs.log('diff found: ' + diff);

gs.eventQueue('Expired_warranty_SM ',policy,no);// pass your event name

}

 

}

View solution in original post

26 REPLIES 26

will the required is an email notification 😞 

Mike_R
Kilo Patron
Kilo Patron

I suggest using Flow Designer. This can be achieved quite easily. We do something similar for consultant accounts that are about to expire.

 

find_real_file.png

this sound ok but where to specify the condition that will expire 30 days ahead ? 

In Action 1 where you lookup the records. You can specify conditions

S_matar
Tera Expert

Dears , 

 

Thank you all for your help but i dont know what is the wrong , 

please check with me my steps :

i have created the event : 

then i created the notification : 

then i created the scheduled job . 

i got the notification i ran it yesterday 25/11/2019 by email but the problem is that i got it for the assets which is already expired . and only for the date 27/10/2019 

( one month before and one day only ) 

please help