- 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
11-26-2019 12:24 PM
Are you sure your event triggered correctly from the code attached as a screen-shot?
- It appears to show additional white space in the event name in gs.eventQueue?
Ignoring the whitespace and based on the code that is attached, ‘diff == -30’ would possibly have triggered for the record that was dated 27/10/2019, as it was 30 days ago.
Did you validate your data to ensure you had records with warranty_expiration timestamps that would trigger events? I’d suggest some testing in sub-prod with some logging\debugging configured and a little manual date manipulation to ensure the functionality is correct.
I don’t think you need to use getElement() as you can dot walk directly to the warranty_expiration and I’d also suggest that you should always include code details in a text format - A screen shot doesn’t allow anyone to do anything without retyping from scratch, so it’s only good for a quick visual inspection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 11:39 PM
yes it is with a white space ,
i used get element as when i put dot only im getting error . i checked () and . and , and everything dunno what was the issue that why i used get element .
my dev instance unfortunately is not cloned from prod and i am unable to due to some errors .
honestly im new to service now with limited developing experience by reading only , . so what i was able to do it to modify the code and execute now every time to see if i am getting only email the correct results or not .
i have changed few in the code and just now i executed i got the assets which their warranty expiration is on 27/01/2020
(( it is next year ))
dunno where is the mistake yet .
this is my code .
var policy = new GlideRecord('cmdb_ci');
var today = gs.nowDateTime();
var query = '^state=published';
policy.addEncodedQuery(query);
policy.query();
while (policy.next()){
var total = gs.dateDiff(today,policy.getElement('warranty_expiration'), true);
var diff = Math.floor(total/86400);
var no =policy.number;
var own = policy.owner.getDisplayValue();
if ((diff == 60) || (diff == 30) || (diff == 10)){
gs.eventQueue('Expired_warranty_SM ',policy,no);
}
if ((diff == -10)||(diff == -30)){
gs.eventQueue('Expired_warranty_SM ',policy,no);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2019 12:14 AM
So the code above does actually generate sys_event records ? and you can see the events in the event log aka sysevent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 03:23 AM
working perfectly with a result of next years
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2019 09:20 PM
yesterday 7/12/2019 i got notified for the assets which will expire on 7/2/2020
i need only before one month 😞
and i am using the above code .
can some one help ?