How Auto populate country name in child locations

Nani18
Tera Contributor

Hello Experts,

 

In locations(cmn_location) table if location type(dropdown) = country than the name must be copied to the Country(string) attribute, including all Child records.

 

 

Nani18_0-1691586947311.png

 

before update and insert business rule is working for me but i want onload client script

 This is the business rule script
var Ltype = current.cmn_location_type.getDisplayValue();
 
    if (Ltype == 'Country') {
        current.country = current.name;
    }
    var pn = current.parent;
    var lcn = new GlideRecord('cmn_location');
    lcn.addQuery('sys_id', pn);
 
    lcn.addQuery('cmn_location_type', 'Country');
 
    lcn.query();
    if (lcn.next()) {
        current.country = pn.country;
 
 
    }

 

How to achieve this by using onload client script.

 

 

Thanks in advance,

 

Best Regards,

Nani

5 REPLIES 5

SwarnadeepNandy
Mega Sage

Hello,

 

@Ankur Bawiskar  is right, there is no point running Client Script onLoad() on location form. It will not save the data on the child location table as well.

And everytime you open the record the Client Script will run.

Better you can use Display BR, so first time each record is opened, it will calculate and save the value on the record.

 

Kind Regards,

Swarnadeep Nandy