Update the priority field as T0 in business service table

Joshuu
Kilo Sage

Hi All,

 

There is a field on the impact analysis table as Recovery Tier. Whenever this is updated as "Tier 0". It should check the applies to field from the same table and find business application and from there check the downstream relationships and find business service. In business service table we need to update the priority field as T0.

 

I have written the below script, but it is not working. It is after update business rule. Please correct me if I am wrong.

 

(function executeRule(current, previous /*null when async*/) {

    var appliesTo = current.applies_to;

    // Ensure Applies To is a Business Application
    if (appliesTo) {
        var appRecord = appliesTo.getRefRecord();
        if (appRecord && appRecord.sys_class_name == 'cmdb_ci_business_app') {

            var grRel = new GlideRecord('cmdb_rel_ci');
            grRel.addQuery('parent', appliesTo);
            grRel.query();

            while (grRel.next()) {
                var childRecord = grRel.child.getRefRecord();
                if (childRecord && childRecord.sys_class_name == 'cmdb_ci_service') {
                    childRecord.u_priority = 'T0';
                    childRecord.update();
                }
            }
        }
    }

})(current, previous);

Joshuu_0-1747762828723.png

 

Joshuu_1-1747762866123.png

 

Joshuu_2-1747762896349.png

 

Joshuu_3-1747762926323.png

 

Please assist.

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Joshuu 

did you add gs.info() and see what came in logs?

1 change is there in your script

(function executeRule(current, previous /*null when async*/ ) {

    var appliesTo = current.applies_to;

    // Ensure Applies To is a Business Application
    if (appliesTo) {
        var appRecord = appliesTo.getRefRecord();
        if (appRecord && appRecord.sys_class_name == 'cmdb_ci_business_app') {
            gs.info('Record found');
            var grRel = new GlideRecord('cmdb_rel_ci');
            grRel.addQuery('parent', appliesTo.getUniqueValue());
            grRel.query();
            while (grRel.next()) {
                gs.info('Relationship found');
                var childRecord = grRel.child.getRefRecord();
                if (childRecord && childRecord.sys_class_name == 'cmdb_ci_service') {
                    gs.info('Inside updating child');
                    childRecord.u_priority = 'T0'; // is field name correct, is the choice value correct
                    childRecord.update();
                }
            }
        }
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader