Background script to mass update Incident resolved_by and resolved_at fields

koliva
Tera Expert

I have installed the plugin to create the resolved_by and resolved_at fields on the incident table. For existing records, I would like to mass populate these fields pulling data from the audit table using crystal reports and import this data into a temp table.

I tried using a background script (FIRST SCRIPT) and it wouldn't work. When it gets to the second while section, it appears to just go into an infinite loop. So I tired to simplify it (SECOND SCRIPT) and just manually set the value and it still goes through an infinite loop. What am I doing wrong?

FIRST SCRIPT:
var gr = new GlideRecord('incident');
gr.addNullQuery('resolved_by');
gr.addNullQuery('resolved_at');
gr.addQuery('number','INC0010019');
gr.query();
var hold_user_sysid = null;
var hold_create_on = null;
while(gr.next()) {
var gr2 = new GlideRecord('u_u_temp_resolve');
gr2.addQuery('u_inc_sysid', '=', gr.sys_id);
while(gr2.next)) {
hold_user_sysid = gr2.u_user_sysid;
hold_create_on = gr2.u_created_on;
gr.resolved_by = hold_user_sysid;
gr.resolved_at = hold_create_on;
gr.setWorkflow(false);
gr_update();
gs.print('Incident #: ' + gr.number + 'has had resolved fields updated: ' + gr.resolved_by + ' ' +
gr.resolved_at);
gs.log('Incident #: ' + gr.number + 'has had resolved fields updated: ' + gr.resolved_by + ' ' +
gr.resolved_at);
}
}




SECOND SCRIPT:
changeResolve();

function changeResolve() {
var gr = new GlideRecord('incident')
gr.addQuery('sys_id', '==', 'c2d983430a0a3c7a002508e125ee2305');
gr.query();
while(gr.next) {
gs.log('Incident #: ' + gr.number );
gr.setWorkflow(false);
gr.resolved_by = '8918cc5f0a0a3c5101932d22406f1647';
gr.resolved_at = '2010-08-30 13:25:56';
gs.log('UPDATE HAS BEEN DONE');
gs.print('INCIDENT ' + gr.number);
}
}

4 REPLIES 4

TJW2
Mega Guru

Either remove the '==' OR make this a single '='

gr.addQuery('sys_id', '==', 'c2d983430a0a3c7a002508e125ee2305');


I get the same results when I remove the == and when I use just the 1 =.


This script is working on DEMO (notice () after gr.next() and the gr.update() lines):
changeResolve();

function changeResolve() {
var gr = new GlideRecord('incident')
gr.addQuery('number', 'INC0090022');
gr.query();
while(gr.next()) {
gs.log('Incident #: ' + gr.number );
gr.resolved_by.setDisplayValue('System Administrator')
gr.resolved_at = '2010-08-30 13:25:56';
gr.update();
gs.log('UPDATE HAS BEEN DONE');
gs.log('INCIDENT ' + gr.number);
}
}


Thank you for helping me! I hate when I don't see silly mistakes like this. 🙂

I appreciate your help.