Background Script to update Multiple Records

cp10
Tera Contributor

Hi team, I want a background script to update the field (category) from the KB knowledge table based on the field (business criticality) from the Business application table.

For example - If the Business criticality field value is platinum then the category field should be updated to platinum by using the background script. I am new to coding, Please advise

1 REPLY 1

chrisperry
Giga Sage

Hi there,

You can use the below background script and add further else if () statements as needed:

var knowGr = new GlideRecord('kb_knowledge');
knowGr.query();
while (knowGr.next()) {
    if (knowGr.cmdb_ci.business_criticality.toString() == 'platinum') {
        knowGr.setValue('category', 'sys_id_of_platinum_kb_category_record_here');
        knowGr.update();
    } else if (knowGr.cmdb_ci.business_criticality.toString() == 'gold') {
        knowGr.setValue('category', 'sys_id_of_gold_kb_category_record_here');
        knowGr.update();
    }
}

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry