- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 01:31 AM
Dears ,
Can some one assist on how to create a notification one month before the warranty expiration date for the assets .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 09:13 PM
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
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2019 10:32 PM
Hi,
You can use the below script to get the event triggered only 30 days before warranty expiration date.
var gr = new GlideRecord("cmdb_ci");
gr.addEncodedQuery('state=published^warranty_expirationRELATIVEEE@dayofweek@ahead@30');
gr.query();
gr.next();
if(gr.hasNext()){
while(gr.next()){
gs.eventQueue('Expired_Warranty_SM',gr,gr.number);
}
}
Please mark my answer as Correct and Helpful based on the impact.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2019 11:38 PM
hi dear , thank you for your reply .
i tried your code but unfortunately no result . i am generating it today 9/12/2020 and i tried to execute it but it doesn't work no result are coming for 7/1/2020 or 8/1/2020 or 9/1/2020 or even 10/1/2020
no notification 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2019 11:41 PM
i copied and pasted the same code and tried when event is fired or even triggered both didnt work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 12:36 PM
Could you please give a try with below script, I just modified my previous script a bit.
var gr = new GlideRecord("cmdb_ci");
gr.addEncodedQuery('state=published^warranty_expirationRELATIVEEE@dayofweek@ahead@30');
gr.query();
if(gr.hasNext()){
while(gr.next()){
gs.eventQueue('Expired_Warranty_SM',gr,gr.number);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 09:05 PM
Dear Thank you very much for your assistance i have a code that worked perfectly now i will post it below .