Copy parent field value to child record when create new record

attanhes
Tera Guru

Hi,

I have added task extended table (task_time_worked) to incident form through related list. I wanted to populate some fields value from parent record to child record (Incident==>Time worked) when user click on new record.

This question has been asked few times in community, unfortunately i could not make my business rule working.

Can someone please help me with this?

find_real_file.png

I have created a before business rule with below code. Unfortunately it doesn't work. Please help me

var gr = new GlideRecord('incident');
gr.addQuery('number', current.sys_id);
gr.query();
if(gr.next())
   {
   current.u_primary_task = gr.number;
       
   }

 

 

 

 

 

8 REPLIES 8

shloke04
Kilo Patron

Hello,

Just write a Display Business Rule on your Related List Time Worked Table as per the script mentioned below:

Script:

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

// Add your code here
displayData();

function displayData(){
if(current.isNewRecord()){
if(current.parent.field_name){   
current.u_primary_task = current.parent.number;
}

}
}

})(current, previous);

 

In the above script, Replace "parent" id required with the field name on your related list table which is referring to your Incident Table. For me it was "parent".

 

Hope this help. Please mark the answer as helpful/correct based on impact.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi Shloke,

Many thanks for the update, but still i could not make this working. This is the cord i tried in my script.

I am missing something. Could you please kindly review this and let me know?

find_real_file.png

 

Many thanks

siva_
Giga Guru

Even if you can have a custom ui action for that related list instead of that new button if you can use a seperate new button you can even pass the parameters in the URL and you can parse the  URL and set the field values on load of the form .let me know if you have any queries on this kind of approach

Hope that helps 

Thanks,

Siva

Mark this response as correct if that really helps 

Inactive_Us1957
Kilo Guru

Hi 

1) Got the form layout of "Time Worked" table by right click on the header.

2) Select the field "Task" field and click on "tree icon" then select the field that you want to show on the form.

For example :

Hope this will work.

Thanks,

Kanchan