Clear RITM variable data

Henrik Jutterst
Tera Guru

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?

1 ACCEPTED SOLUTION

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

View solution in original post

9 REPLIES 9

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

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);
    }
}

Hi Jim and thanks for the update.

You are totally right on this. Dot-walking like you did is a better solution.

dvp
Mega Sage
Mega Sage

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

 

Thanks for the comment but I don't think this solution can clear variables in a RITM as far as what I can see.