The CreatorCon Call for Content is officially open! Get started here.

Script to run on records not updated for over 48 hours or more?

Edwin Fuller
Tera Guru

I've written the below script which works fine. However, I need it to run on records that have not been updated for 48 hours OR MORE. I believe right now its only running on records that haven't been updated for 48 hours, and not records that was updated more then 48 hours ago. Could someone help me incorporate the OR More part into my script?

var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");

gr.addEncodedQuery('sys_updated_on<javascript:gs.daysAgoStart(2)');

gr.addQuery('audience','!=','Client');

gr.addQuery('audience','!=','Other');

gr.addQuery('current_status','!=','Complete');

gr.addQuery('current_status','!=','Requestor Canceled');

gr.addQuery('current_status','!=','Closed-CCCU Reported');

gr.addQuery('current_status','!=','Clarification Needed');

gr.addQuery('current_status','!=','Draft');

gr.addQuery('current_status','!=','Acknowledged');

gr.addQuery('current_status','!=','In Progress');

gr.addQuery('current_status','!=','Client Request Not Met');

gr.addQuery('current_status','!=','Rebuttal Submitted');

gr.addQuery('current_status','!=','Rebuttal Rejected');

gr.addQuery('current_status','!=','New');

gr.addQuery('current_status','!=','Complete - AutoClosed');

gr.query();

while(gr.next()){

gs.eventQueue('x_hemas_connectus2.closeinternal',gr, gr.current_person_assigned,gr.sys_created_by);

}

1 ACCEPTED SOLUTION

damodarreddyp
ServiceNow Employee
ServiceNow Employee

Hi Edwin, You have to use 'daysAgo(2)' instead of 'daysAgoStart(2)'.



Ex: Current Time - 2017-01-23 07:25:00


daysAgo(2) - will take 48 hours --> This will return '201-01-21 07:25:00'


daysAgoStart(2) - this will take start of 2 days ago --> This will return '201-01-21 00:00:00'



So by changing your query as below should work:


var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.addEncodedQuery('sys_updated_on<javascript:gs.daysAgo(2)');




Hope this helps.



With Regards,


Damodar


View solution in original post

2 REPLIES 2

Mike Allen
Mega Sage

What I always find useful is getting all the records I want to change in a list and copying the query from that and putting it in an encoded query:



find_real_file.png


active=true^priority=1^assignment_group=8a4dde73c6112278017a6a4baf547aa7^sys_updated_on<=javascript:gs.dateGenerate('2016-11-15','11:40:45')


damodarreddyp
ServiceNow Employee
ServiceNow Employee

Hi Edwin, You have to use 'daysAgo(2)' instead of 'daysAgoStart(2)'.



Ex: Current Time - 2017-01-23 07:25:00


daysAgo(2) - will take 48 hours --> This will return '201-01-21 07:25:00'


daysAgoStart(2) - this will take start of 2 days ago --> This will return '201-01-21 00:00:00'



So by changing your query as below should work:


var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.addEncodedQuery('sys_updated_on<javascript:gs.daysAgo(2)');




Hope this helps.



With Regards,


Damodar