
- 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-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-09-2020 02:56 PM
I stumbled across this thread today, I think using the question is not the way to go as it is just a label; should really use the name of the variable itself. This would greatly simplify your code as you could update directly from ritm variables instead of crawling into the variable tables.
IE:
//add variable name into function below to clear it
clearVariable('name');
function clearVariable(variableName) {
try {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name', 'Background check');
ritm.query();
while (ritm.next()) {
ritm.variables[variableName] = '';
ritm.Update();
}
}
catch (ex) {
gs.info('Exception is: ' + ex);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 11:28 PM
Hi Jim and thanks for the update.
You are totally right on this. Dot-walking like you did is a better solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 02:44 AM
I think your requirement best fits with Data archiving.
Here is the ldocs ink
https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/database-rotation/concept/c_ArchiveData.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 11:05 AM
Thanks for the comment but I don't think this solution can clear variables in a RITM as far as what I can see.