Fix Script - Populate new field on historic records

Kiera Mears
Mega Guru

Hi,

We have a custom application and have added a new field to populate with a value based on the category and subcategory (for where the work can be completed). E.g. if Category is X and Subcategory is Y, then work location is C.

We have this set up for any new records using a matrix, but need to run a fix script on historic records.

Any suggestions? Coding isn't my strongest area!

Thanks,

Kiera

1 ACCEPTED SOLUTION

Kiera Mears
Mega Guru

I resolved this myself, I copied the business rule that was being used into a fix script and amended it slightly to function as required. Mainly ensuring it's looking at the correct tables and changing 'current' to the relevant variable name, and added an 'if empty' condition so it wouldn't have to repeatedly go through the same 40,000 records.

Thanks all for your inputs!

View solution in original post

8 REPLIES 8

sonali panda1
Kilo Sage

Hi,

Try the below script in lower instance after changing table name, x, y, and location and C.

var rec = new GlideRecord('tablename');

rec.addEncodedQuery('category=X^subcategory=Y');

rec.query();

while(rec.next())

{

rec.location = C; // C needs to be checked as in sysid as location will be a reference field. Else as C.name

rec.update();

}

//Replace all the labels and values with correct label and value. Do check first in lower instance.

This seems to work one by one, but there are over 50 I'll need to update. Is there anything you can suggest for that?

I guess there is some business rule which is obstructing it. Can you add a line in between as rec.setWorkflow(false);

 

var rec = new GlideRecord('tablename');

rec.addEncodedQuery('category=X^subcategory=Y');

rec.query();

while(rec.next())

{

rec.setWorkflow(false);

rec.location = C; // C needs to be checked as in sysid as location will be a reference field. Else as C.name

 rec.update();

}

 

Do check when you run the script what is the message it shows in the background script. Did you see like some slow running business rule or some message? Try with setting the workflow false.

Did you get a chance to check this ?