When record is created in related List, it has to set in the Parent table field.

Munna1
Tera Contributor

Hi Everyone,

Here there are two tables called Model (Parent table) and Packaging Data (Related list).

Here when record is created in the Packaging Data related list. it has to set the AppID value in the AppTrackID field in Model parent table. Please help me with the script, how we can achieve this..

 

Munna1_0-1711042467311.png

 

Thanks,

 

 

3 REPLIES 3

James Chun
Kilo Patron

Hi @Munna1,

 

You can do one of the following:

  • Use a relationship with a filter
    • Navigate to System Definition > Relationships
    • Create a new relationship (or use the existing relationship) and add a query, something like:

 

current.addQuery('app_id=' + parent.getValue('app_Id'));

 

  • Add the related list (If not already there) and if you create a new Packaging Data record, the field(s) specified above will be automatically populated

 

  • Use a Business Rule
  • Not sure how those two records are related but if they are related by a reference record (e.g. parent/child), you can write a before BR on insert

Cheers

Hi James,

Thanks for your response 

 

But I have tried with this Relationship. But it is not working.

Here Parent /child table are related by a reference field called Model. and I am trying with the Before -Insert BR. But it is not working as expected.

 

    var grd = new GlideRecord('sn_packaging_data');      //Related list table name
    grd.addQuery('sys_id',current.u_software_model);      
    grd.addQuery('u_apptrack_id',current.u_app_id);
    grd.query();
    if(grd.next()){
        grd.setValue('u_apptrack_id',current.u_app_id);
    }

 

Hi @Munna1,

 

I believe you should be creating the BR on the Packaging Data table.

And the script should be something like:

 var grd = new GlideRecord('cmdb_model');
 grd.get(current.getValue('u_software_model'));
 if (grd.isValidRecord()) {
     current.setValue('u_apptrack_id', grd.getValue('u_apptrack_id'));
     current.setValue('u_app_id', grd.getValue('u_app_id'));
 }

 

Note that this will overwrite the two fields even if the user provides a value for them.

 

Cheers