Update the priority field as T0 in business service table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 10:43 AM
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);
Please assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 11:58 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 02:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 08:39 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 01:29 PM
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