
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 01:01 AM
Hi there,
I'm looking for a way to erase the values of a variable in a RITM that is more then 90 days old. After a year from creation I want to delete the RITM (but that's no issue since I assume that all related variables will be deleted when the RITM is deleted)
So, if a RITM variable is called 'user' I'm looking for a way to clear that value if the RITM is more then 90 days old. This will be a scheduled activity in some way.
Any ideas?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 11:03 AM
Hi and thanks for the feedback.
I ended up with this script but if was never really put into production. If it's helpful to anyone feel free to use it:
//add variable question into function below to clear it
clearVariable('Name');
function clearVariable(variableName){
try{
var ritmSysID;
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name','Background check');
ritm.query();
while(ritm.next()){
ritmSysID = ritm.sys_id;
//gs.print('ritmSysID: ' + ritmSysID);
//use this sys_id to look up variable
var varTable = new GlideRecord('sc_item_option_mtom');
varTable.addQuery('request_item',ritmSysID);
varTable.addQuery('sc_item_option.item_option_new.question_text',variableName);
varTable.query();
while(varTable.next()){
gs.print('Q: ' + varTable.sc_item_option.item_option_new.question_text + ' A: ' + varTable.sc_item_option.value + ' ');
varTable.sc_item_option.value = '';
varTable.sc_item_option.update();
}
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
}
Kind Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 02:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 02:15 AM
Hi Henrik,
you can have a scheduled job for this; which runs daily and Run as System Admin and have following script
variable values are stored in sc_item_option_mtom table; try running this first by giving one query as
ritmRec.addEncodedQuery('number=RITM0001');
then visit the sc_item_option_mtom table and check records exist or not
clearValues();
function clearValue(){
try{
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLast3Months()');
ritmRec.query();
while(ritmRec.next()){
var ritmSysId = ritmRec.sys_id;
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', ritmSysId);
gr.query();
while(gr.next()){
gr.deleteRecord();
}
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 03:48 AM
Hi Ankur and big thanks for the feedback!
Regarding the [sc_item_option_mtom] table query. Do you know if there is a record for each variable related to a RITM?
Let's say that I want to clear (not delete) what is written into a variable called 'user'. How is that done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 06:14 AM
Hi Henrik,
So if you want to clear the value only then it is stored in this table; update code as below and test once
clearValues();
function clearValue(){
try{
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLast3Months()');
ritmRec.query();
while(ritmRec.next()){
var ritmSysId = ritmRec.sys_id;
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', ritmSysId);
gr.query();
while(gr.next()){
var refRecord = gr.sc_item_option.getRefRecord();
refRecord.value = '';
refRecord.update();
}
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader