Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch records which are having scheduled retirement date in next 3 months from now?

Sreeja3
Giga Contributor

Hi Team,

I have a requirement to fetch the records from cmdb_ci_computer table which is having asset.retirement date within 3 months from now.

Initially we were asked to fetch the records having retirement date on next week so I queried form the filter directly.

Here is the script

var gr = new GlideRecord('cmdb_ci_computer');
gr.addEncodedQuery('asset.install_statusNOT IN7,8^asset.retirement_dateBETWEENjavascript:gs.beginningOfToday()@javascript:gs.endOfNextWeek()');

gr.query();

while (gr.next()) {

gs.eventQueue("assignto_asset_refresh_event", gr);

}

But I have no idea how can I fetch the records having retirement date 3 months from now.

Any help would be highly appreciated. Thanks in advance.

Regards,

Sreeja

9 REPLIES 9

You need to add one more filter. Try this out, it should work

asset.retirement_dateRELATIVELE@dayofweek@ahead@90^asset.retirement_dateRELATIVEGE@dayofweek@ago@90

 

find_real_file.png

Let me know once it worked.

Hi Alikutty,

I tried with your filter but its taking all the previous records as well which are 90 days before from now.

find_real_file.png

 

Regards,

Sreeja

My bad, I misunderstood the conditions. Try this one

find_real_file.png

Hello,

Has this worked for you?

 

Pranay Tiwari
Kilo Guru

Hi,

 

paas this query "asset.retiredONThis quarter@javascript:gs.beginningOfThisQuarter()@javascript:gs.endOfThisQuarter()"