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

It's to remove personal information. For example where someone has provided an alternative address for something to be collected/delivered.

 

Request item is submitted --> Request item is worked on and closed --> 30 days later variables should be cleared.

Hi @arobertson 

 

Better to hide those via UI policy instead of removing. or use ACL.

 

@Anurag Tripathi  Thoughts please.

*************************************************************************************************************
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]

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

I usually don't like to delete it too , because it may come back form a compliance / Data retention policy side of things and bite in future, but if the data contains pii it might be important to delete. But be sure to check the company policy on the same.

-Anurag

OlaN
Giga Sage
Giga Sage

Hi,

As an alternative, you can create a Flow that does the same. No scripting required.

Providing a simple example below.

 

flow-clear-variable-data.png