- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 08:53 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 07:56 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2017 03:00 AM
Hi Ankur,
I tried it today, but no luck.
Thanks,
Rafi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2017 01:38 AM
Hi Rafi,
Can you share the code which you updated in that script include?
Regards
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
‎09-28-2017 03:36 AM
Hi Ankur,
Here is the code I changed in _queryIsets. I would like to test with 3 days first.
_queryIsets : function() {
var gr = new GlideRecord('sys_import_set');
gr.setLimit(this.isetsChunk);
if (this.table)
gr.addQuery('table_name', this.table);
if (this.daysAgo > 0){
if(this.table == 'u_cgi_remedy_reply'){
gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + 3);
}
else{
gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + this.daysAgo);
}
}
gr.query();
var isets = new Array();
while (gr.next()) {
this._log('Cleaning import set ' + gr.number);
isets.push(gr.sys_id + '');
}
return isets;
},
Thanks,
Rafi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2017 04:01 AM
Hi Rafi,
Did you add log statements in the script include function. I have added you can also add and check in system log table.
_queryIsets : function() {
gs.log('Rafi inside queryIsets method');
var gr = new GlideRecord('sys_import_set');
gr.setLimit(this.isetsChunk);
if (this.table)
gr.addQuery('table_name', this.table);
if (this.daysAgo > 0){
if(this.table == 'u_cgi_remedy_reply'){
gs.log('Rafi inside table is remedy reply');
gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + 3);
}
else{
gr.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@' + this.daysAgo);
}
}
gr.query();
var isets = new Array();
while (gr.next()) {
this._log('Cleaning import set ' + gr.number);
isets.push(gr.sys_id + '');
}
return isets;
},
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 07:43 AM
Hi Rafi,
Any update on this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader