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

Tony Chatfield1
Kilo Patron
Hi, you could run a scheduled job, query the table involved and trigger a sys_event for every record that meets your criteria IE warranted date is between X and y. Then use the sys event to trigger a notification. If the notifications always go to the same person or group, I would use a scheduled report instead of a notification, as way less spam involved.

can you check my code below ? 

Kajal Goti
Mega Guru

Hello,

 

You can achieve this with help of Scheduled Job.

What you want exactly like You want to notify user whose warranty date is around? notify user daily once warranty date is around.?

If so then create scheduled job like this and give criteria as per your warranty date .

find_real_file.png

GlideRecord('Your table name')

addQuery("warrenty_date",value)

 

gs.eventQueue("give name as per your naming convention of event notification)

Please mark as correct and helpful,If you find any help worthy.

 

not user , to notify me . and the service desk .