Auto create child record when record inserted on parent table - Related list (BR)

Service Manager
Kilo Guru

HI All,

I need help to auto create the record in related list when record is inserted on Parent table

BR on after on Insert is being created on parent table "abc" and child table is "xyz".However the records is getting created on child table on insert of record on parent table "abc"  but unfortunately we cannot link in related list 

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

// Add your code here
var nr = new GlideRecord('result_activity');
gr.initialize();
gr.access = current.result.system_application.u_name;
current.access = current.result.name;

gr.insert();

})(current, previous);

Thanks

1 ACCEPTED SOLUTION

This is what i understood from your requirement.

You have parent table A and child tables B and C.

You configured related list on form A and related list is pointing to table B.

You need to have reference or system relationships to maintain relationship between table A and B.

 

But, you stated that your reference to table A is in table C.

You need to write business rule on table C to push table A reference to table B. This should resolve your issue.

 

Regards,

Sachin

 

View solution in original post

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

I assume that you have reference field on child table which refers parent.

You will have to pass current sys_id of parent record while creating child record like below

 

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

// Add your code here
var nr = new GlideRecord('result_activity');
gr.initialize();
gr.access = current.result.system_application.u_name;
current.access = current.result.name;

current.parent = current.sys_id;

gr.insert();

})(current, previous);

 

Regards,

Sachin

Hi 

 

Thanks for your response !

Yes I have a reference field on child table and when I manually update the reference field "result" in child table then I could see in the parent table as expected 

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

// Add your code here
var gr = new GlideRecord('result_activity');
gr.initialize();

gr.access_grant = current.result.name;
gs.addInfoMessage(gr.access_grant);
current.result= current.sys_id;


gr.insert();

})(current, previous);

 

I tried with both current.parent = current.sys_id and current.result = current.sys_id

it didn't work

 

Thanks

Please modify your code like below

 

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

// Add your code here
var gr = new GlideRecord('result_activity');
gr.initialize();

gr.access_grant = current.result.name;
gs.addInfoMessage(gr.access_grant);
gr.result= current.sys_id;


gr.insert();

})(current, previous);

 

Regards,

Sachin

Please modify your code like below

 

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

// Add your code here
var gr = new GlideRecord('result_activity');
gr.initialize();

gr.access_grant = current.result.name;
gr.result= current.sys_id;
gr.insert();

gs.addInfoMessage(gr.access_grant);

})(current, previous);

 

Regards,

Sachin