Trying to change state of Deduplication task records

pvvn
Tera Contributor

Hi All 

There is a table reconcile_duplicate_task which i am trying to glide the records and change the state of records which are created after 90 days to Closed Skipped.

I have Used Fix Script/ Scheduled Job to run, before executing want to find how many records are available to do.

So i used background script to find the records, but unable to get count.

below is the script written for Scheduled Job

pvvn_0-1699183506019.png

 below is fix script 

 

var gr = new GlideRecord('reconcile_duplicate_task');
gr.addQuery('state','Open');
gr.addQuery('u_created_date','<','gs.beginningOfLast3Months()');
gr.query();
gr.getRowCount();
while(gr.next()) {
    gr.state = "Closed Skipped";
    }  .
 
 
While finding preference records the errors are as below
pvvn_1-1699183786461.png

 



I need your Suggestions on this and if any wrong please guide me to correct it.
 
 
Thanks 
Pvvn
4 REPLIES 4

Bert_c1
Kilo Patron

Hi Pvvn,

 

Try the following changes to your script.

 

var gr = new GlideRecord('reconcile_duplicate_task');
gr.addQuery('state','Open');
//gr.addQuery('u_created_date','<','gs.beginningOfLast3Months()');   // no custom field in my instance.
gr.addQuery('sys_created_on','<','gs.beginningOfLast3Months()');
gr.query();
gs.info('Number of reconcile_duplicate_task records in last 3 months = ' + gr.getRowCount());
while(gr.next()) {
//    gr.state = "Closed Skipped";
    gr.state = 7;  // the choice value is 7 for "Closed Skipped" OOB
    gr.update();
}
 

Your screenshot show a different script. the 'state' field is inherited from task, and the value 7 is used for "Closed Skipped" OOB.  The "Run as" user value probably doesn't have read access to the two tables shown in the Error you're getting. And my Scheduled Script Execution records in sysauto_script table do not start with a function declaration, without a line to call that function, outside of the function definition.

pvvn
Tera Contributor

Hi Bert,
Thanks for your Help.
As you suggested i have made changes and i tried it but its showing no records(Zero) while records are there.
Any suggestions over here.

Thanks

pvvn

Bert_c1
Kilo Patron

Hi Pvvn,

 

Go to a list view of reconcile_duplicate_task records, build a filter condition like you have in your script, and see what records you get.  If you see what you expect, then right-click on the filter breadcrumbs and select "Copy query", use that in  

gr.addEncodedQuery('[query_string]');

in place of the 'gr.addQuery();' line and see if the script shows records.  If not, I suggest you create a Support Case for what results your get.  Try your script logic in Scripts - Background as 'admin' user.

Tiago Duarte
Tera Contributor

Hi,

I think you don't get results because you are using

gr.addQuery('state', 'Open');

instead

gr.addQuery('state', '1');