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);
2 REPLIES 2

glideFather
Tera Patron

ahoy @Chandrika4,

 

have you tried to log your BR? The field that you plan to populate is it a string, reference or what type? And same for the parent, are they 1:1?

 

Then it will might require different approach based on the data types...

 

What you can do is to try this behaviour in a background script and once you manage to update it on one selected record then you can apply on the BR level.


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

Hi,

 

It is a reference field to CI table. I have tried putting logs, it seems the BR is not triggering at all.