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

 

View solution in original post

20 REPLIES 20

Lovely
Tera Contributor

For 1 point You can use below script:

you can create a Before Insert BR on that table where you are inserting a record like table1.

var gruser = new GlideRecord('table2');
gruser.initialize();
gruser.first_name=current.u_first_name;
gruser.last_name=current.u_last_name;
gruser.email = current.u_email;
gruser.user_name = current.u_name;
gruser.insert();

You can rename the variables as per your requirement.

For point 2 both tables must have some linkage then only we can update a record.

 

Thanks,

Lovely.