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

John Gilmore
Giga Guru

@Joshuu,

You have an issue with your addquery argument: 

grRel.addQuery('parent', appliesTo);


AppliesTo in this use passes the glide element not the sys_id so you have a mismatch in data types between the parent field and what you passing to it.

Try using this instead:

grRel.addQuery('parent', appliesTo.sys_id); //or because its a glide element appliesTo.getValue() should also work.

 

Hi @John Gilmore ,

 

I have tried this too, but it is not working.

@Joshuu 
I can't see anything else in you script that would be a problem. The only thing that stands out that could be an issue is the configuration of the u_priority column that you are updating at the end. Verify that it is configured correctly and that 'T0' is a valid value for the field.

James Chun
Kilo Patron

Hi @Joshuu,

 

Your script looks ok to me, I tried something similar in my PDI and it's working form my end.

Ty adding some log like below:

(function executeRule(current, previous /*null when async*/ ) {
    gs.info('Joshuu testing:  ' + 'Beginning of BR');
    var appliesTo = current.applies_to;

    // Ensure Applies To is a Business Application
    if (appliesTo) {
        gs.info('Joshuu testing:  ' + 'Inside the appliesTo IF');
        var appRecord = appliesTo.getRefRecord();
        if (appRecord && appRecord.sys_class_name == 'cmdb_ci_business_app') {
            gs.info('Joshuu testing:  ' + 'Inside the appRecord IF');
            var grRel = new GlideRecord('cmdb_rel_ci');
            grRel.addQuery('parent', appliesTo);
            grRel.query();

            while (grRel.next()) {
                gs.info('Joshuu testing:  ' + 'Inside the grRel WHILE');
                var childRecord = grRel.child.getRefRecord();
                if (childRecord && childRecord.sys_class_name == 'cmdb_ci_service') {
					gs.info('Joshuu testing:  ' + 'Inside the childRecord IF');
                    childRecord.u_priority = 'T0';
                    childRecord.update();
                }
            }
        }
    }

})(current, previous);

 

If you are able to see all the logs, maybe there is something else that is blocking you to update the value of 'u_priority'.

 

Cheers