Update the company values from one to another on all the tables

Rohith25
Tera Contributor

Hello All,

 

we had requirement that to update the records of company field of all the tables (apart cmdb_ci table)which company value "1" having previously now it need to change as "2".

 

var gr = new GlideRecord('sys_dictionary');
gr.addEncodedQuery('reference.labelSTARTSWITHcompany^nameNOT LIKEcmdb_ci');
gr.query();
while (gr.next()) {
    var table_name = gr.name;
    var colum = gr.element;
    var en = colum + "=" + 'b5b69a55dbda220069febedffe9619d9';// value "1" 
    var chk_rec = new GlideRecord(table_name);
    chk_rec.addEncodedQuery(en);
    chk_rec.query();
    while (chk_rec.next()) {
        chk_rec.colum = 'af7fcd77878321d0d1bb21bc8bbb3503';// value "2"
        chk_rec.setWorkflow(false);
        chk_rec.autoSysFields(false);
        chk_rec.update();
    }
}
When I run on fix script it was running not updating. Could anyone help me on this.
1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

Your found records don't have a 'colom' field. Can you try your while like this:

while (chk_rec.next()) {
    chk_rec[colum] = 'af7fcd77878321d0d1bb21bc8bbb3503'; // value "2"
    chk_rec.setWorkflow(false);
    chk_rec.autoSysFields(false);
    chk_rec.update();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

Your found records don't have a 'colom' field. Can you try your while like this:

while (chk_rec.next()) {
    chk_rec[colum] = 'af7fcd77878321d0d1bb21bc8bbb3503'; // value "2"
    chk_rec.setWorkflow(false);
    chk_rec.autoSysFields(false);
    chk_rec.update();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders When I run it was taking long time more than 45 mins but it can see no records got updated.

You said no records were updated, but did accept my solution? Did it work after all?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Yes Correct after refresh the page it got worked