Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Auto-Populate a reference field of parent table with the name of the Child

Chandrika4
Tera Contributor

Hi Team,

 

Can you please guide me regarding the After Business Rule to Auto populate a custom field named as"Physical Host Name" on a Parent Server record with the Child name once a CI Relationship is created. 

Below is my sample script: 

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

    // Add your code here
    var gr = new GlideRecord(current.getRecordClassName());
    if (gr.get(current.parent)) {
        if (!gr.u_physical_host_name) {
            gr.u_physical_host_name = current.child;
            gr.update();
        }
    }

})(current, previous);
9 REPLIES 9

the screenshot is terrible quality, please when asking for help provide a readable one...

 

I cannot evaluate the trigger myself, but what you can do is TEMPORARILY change the condition to just one condition, e.g. "Parent class" [IS] "Server", then try to trigger it.

 

BTW what is the operator "IS A"?


✂-----Cutting-out-the---✦AI-noise✦---All-replies-written-and-vouched-for-by-GlideFather---

@Chandrika4 you can also try to change it from "IS A" to "IS":

glideFather_0-1786344454078.png

 


✂-----Cutting-out-the---✦AI-noise✦---All-replies-written-and-vouched-for-by-GlideFather---

Hi @glideFather ,

Changed the Operator, still facing issues. 

Chandrika4_0-1786346108758.png

 

 

try to keep just one single condition or not at all, to make it more trigerrable or check the script in a background script, have you logged it to see if it is triggered?


✂-----Cutting-out-the---✦AI-noise✦---All-replies-written-and-vouched-for-by-GlideFather---

NityaB161013953
Giga Patron

Hi @Chandrika4 ,

The issue is with how the parent CI is being retrieved. Since this Business Rule is on cmdb_rel_ci, you should get the parent using current.parent.getRefRecord() rather than current.getRecordClassName().

Also, since u_physical_host_name is a reference field, assign the child CI’s sys_id/reference, not its name.

(function executeRule(current, previous) {

    var parentCI = current.parent.getRefRecord();

    if (parentCI.isValidRecord() && !parentCI.u_physical_host_name) {
        parentCI.u_physical_host_name = current.child;
        parentCI.update();
    }

})(current, previous);

Make sure the Business Rule is configured on cmdb_rel_ci with After → Insert and temporarily remove any condition while testing. If the BR still doesn’t trigger, check that the CI relationship is actually being created on cmdb_rel_ci.