Need to include a condition in script include 'ImportSetCleaner'

mdrafi
Mega Expert

Hi,

We have a import set table (u_reply), currently only 1 week of data maintained on this table. There is an OOTB Scheduled job 'Import Set Deleter' which is removing the data older than 7 days. It calls OOTB script include 'ImportSetCleaner'.

What I need is, I want to have 30 days of data only for the import set table mentioned above. I am having difficulty in modifying the script as I can't change the value of the variable 'daysAgo' present in the script include, because it affects all the import set tables. As per my analysis, we need to add a condition for this table in '_removeData' function but how to set the 30 days?

Can you suggest on this.

Thanks,

Rafi

1 ACCEPTED SOLUTION

Hi Ankur,



I tried above mentioned code, but it didn't work.



So, I changed the scheduled job script as below and it worked for me. I tested it today only.


However, thanks for your support and help on this.




var gr = new GlideRecord('sys_db_object');



gr.addQuery('super_class.label','=','Import Set Row');


gr.query();


while (gr.next()) {


gs.log('Import Set Tablename is ' + gr.name);



var tblName = gr.name.toString();


var my30DayTable = 'u_cgi_remedy_reply';


if (tblName == my30DayTable)


{


var ic = new ImportSetCleaner(tblName);


// delete import sets and their related import set rows


// that were created more than or equal to 30 days ago


ic.setDaysAgo(30);


ic.clean();


}


else


{


var ic = new ImportSetCleaner(tblName);


// delete import sets and their related import set rows


// that were created more than or equal to 7 days ago


ic.setDaysAgo(7);


ic.clean();


}


}


View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Rafi,



_removeData method calls the _tableClean() method.



_tableClean : function(table) {


          var tc = new GlideTableCleaner(table, this.daysAgo*86400000, 'sys_created_on');


          tc.clean();


    },



in this method set this.daysAgo as 30 if this is your tableName



modified code



_tableClean : function(table) {



if(table == 'u_reply'){


    this.daysAgo = 30;


          var tc = new GlideTableCleaner(table, this.daysAgo*86400000, 'sys_created_on');


          tc.clean();


}


else{


// if not your table then this.daysAgo will be 7


var tc = new GlideTableCleaner(table, this.daysAgo*86400000, 'sys_created_on');


          tc.clean();


}



    },



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur for the response.



I tried that earlier, but from system logs I could see that '_cleanTable' function is called not '_tableClean'.


Hi Rafi,



Are you sure _cleanTable() is called and not _tableClean(). Can you verify this?



if you are sure _cleanTable() is called then there is one method in that script include _queryIsets which has following line of code.


Can you modify to this?



if (this.daysAgo > 0){


if(this.table == 'u_reply'){


                gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + 30);


}


else{


gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + this.daysAgo);


}


}



but verify that this method is called and also check in log value of this.table



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Rafi,



Any update on this?



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader