how we get 1. Create a record in Table2 whenever a record is inserted into Table1. 2. Update Short Description of a particular record of Table2 whenever a record is updated in Table1.

sachin dhek
Kilo Contributor

i am a fresher i am stuck in this problem last 3 days 

1 ACCEPTED SOLUTION

You need to add some query if you want to update existing record.

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

// Add your code here
var gr = new GlideRecord('u_table_1');
gr.addQuery(); // eg. gr.addQuery('fieldName', 'value'); 
//gr.addQuery('active', true);  // eg
gr.query();
//gr.insert();  // use this line if you want to create new record
while(gr.next()){

gs.log(gr.u_table_2); // here use gr.fieldName

gr.fieldName = 'value';
gr.update();  // to update the record matching your query.
 
}

})(current, previous);

 

Note: replace fieldName as per your column/field names in your tables.

 

Thanks,
Anil Lande

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

20 REPLIES 20

script of relationship is not working

configure related list is  not show a parent linked on table 1

This is tested in my PDI and is working correctly. Please share the screenshot of what you have configured , there might be a step which you have missed and hence not getting the result.

Regards,

Shloke

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

Regards,
Shloke

Update Short Description of a particular record of Table2 whenever a record is updated in Table1.

this is my code is this right or not?

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

// Add your code here
var rec = new GlideRecord('u_table2');
//rec.addQuery('u_string_3',current.sys_id);
rec.query();
while(rec.next())
{
rec.u_string_3 = current.u_table_1;
rec.update();
}
})(current, previous);

 

Hi,

Just posting a script will not help you. You need to share the screenshot of the Tables which you have configured.

Also on which Table you have written your Rule is a factor here to decide if your query is correct or not.

I have very clearly mentioned step by step on how to achieve what you are looking for. Have you read what I have posted above?

 

Regards,

Shloke

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

Regards,
Shloke

yes sir. it worked.