Set field value on related list(s) form same as value on form

shanerodgers
Kilo Expert

Hi, when a user creates a new form on the related list, I want the product owner to be auto filled with the same value as the product owner on the form they are creating the related form from.

This is the form where the product owner is filled from:

Pic_2.png

Here you can see the related list below it:

Pic_1.PNG

Here is the form that pops up when you click new, I want to auto fill Product Owner with the same value as PO on the main form. They are both referencing the User table.

Pic_3.png

Any help appreciated!

1 ACCEPTED SOLUTION

Hi Shane,



I've commented a few points below, hope this helps clear up a few things but let me know.



var gr = new GlideRecord('u_gbts_code_release_management');


gr.addQuery('number', current.parent);       //change number to sys_id. current.parent will return a sys_id and you need to match like for like


gr.query();


while(gr.next()) {


current.u_approver2 = gr.u_product_owners;         //product_owners implies plurality, what sort of field is this?


}


gr.update();         //you haven't changed anything on the glide record so this line is not needed.



})(current, previous);


View solution in original post

7 REPLIES 7

Dubz
Mega Sage

Hi Shane,



If the requirement is that whenever the a record is added to the code moves table then, if there is a parent record, the product owner from the parent should be populated on the code moves record you can use a before insert business rule on the code moves table.



var gr = new GlideRecord('sys_release_table')   //check table name


gr.addQuery('sys_id', current.parent);


gr.query();



while(gr.next()){


current.product_owner = gr.product_owner;


}


That's kind of the same as to what I tried, but it didn't seem to work?



Business Rule:


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



var gr = new GlideRecord('u_gbts_code_release_management');


gr.addQuery('number', current.parent);


gr.query();


while(gr.next()) {


current.u_approver2 = gr.u_product_owners;


}


gr.update();



})(current, previous);



Triggers before insert.


Hi Shane,



I've commented a few points below, hope this helps clear up a few things but let me know.



var gr = new GlideRecord('u_gbts_code_release_management');


gr.addQuery('number', current.parent);       //change number to sys_id. current.parent will return a sys_id and you need to match like for like


gr.query();


while(gr.next()) {


current.u_approver2 = gr.u_product_owners;         //product_owners implies plurality, what sort of field is this?


}


gr.update();         //you haven't changed anything on the glide record so this line is not needed.



})(current, previous);


This works perfectly on insert:


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



var gr = new GlideRecord('u_gbts_code_release_management');


gr.addQuery('sys_id', current.parent);


gr.query();


while(gr.next()) {


current.u_approver2 = gr.u_product_owners;


}



})(current, previous);



Thanks for your help. Product Owner is only a single product owner, I'm not sure why it's named as it is. One more question, is it possible to do this onLoad as opposed to on insert? I imagine a client script and script include are needed?



Edit: I changed it to Display and it seems to work onLoad now!