Blank out variables on closed request items closed at least 30 days ago

arobertson
Tera Guru

Hi all.

 

I have the following scheduled job script that should look for a specific catalog item and then clear out certain variables. The variables should only be cleared on request items that have been closed for 30 days.

 

My issue is that how do I get the script to capture request items that may have been closed a year or so ago in the platform.

 

End goal is for this script to run where the closed date is at least 30 days ago.

 

I feel I need to compare the closed date of the request item with today's date and if greater then 30 days clear the variables.

 

 

var q = 'cat_item=d203fe1fdb87fb00fd7db34ffe961923^closed_at<javascript&colon;gs.beginningOfLast30Days()';
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery(q);
gr.query();
while (gr.next()) {
    gr.variables.alternative_address = '';
    gr.variables.sc_street_name_and_number = '';
    gr.variables.sc_zip_code = '';
    gr.variables.sc_city = '';
    gr.variables.other_location = '';
    gr.variables.other_delivery_address = '';
    gr.variables.alternative_address_MACZ = '';
    gr.variables.other_address = '';
    gr.setWorkflow(false);
    gr.autoSysFields(false);
    gr.update();
}

 

 

 

 

Regards.

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

I think you need everything which was closed before last 30 days, for that particular catalog item

If so, then this should work

AnuragTripathi_0-1704380387835.png

 

EncodedQuery:

cat_item=970949824f69f70099f1b3728110c7d6^closed_at<javascript&colon;gs.beginningOfLast30Days()

-Anurag

View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

I think you need everything which was closed before last 30 days, for that particular catalog item

If so, then this should work

AnuragTripathi_0-1704380387835.png

 

EncodedQuery:

cat_item=970949824f69f70099f1b3728110c7d6^closed_at<javascript&colon;gs.beginningOfLast30Days()

-Anurag

That is what I'm using now. I think I was getting myself confused and it is actually working as expected.

So is this thread answered?

-Anurag

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @arobertson 

 

What is use case of same? After closing changing or removing value is not a best pratcie. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************