How to map data between two tables

Shruti07
Tera Contributor
 
9 REPLIES 9

Eshwar Reddy
Kilo Sage

@Shruti07 


Could you please provide more information? That would be very helpful.

I have a requirement where I want to map two tables. when I create data in one table 1. Automatically the same data should be carried as a record in table 2. How can this be achieved

Shruti07
Tera Contributor

I have a requirement where I want to map data between two tables. When I create data in table A, the same data should automatically be copied to table B ,creating a new record in table B also.

@Shruti07

In this case you need to create an after insert business rule on table A. This business rule will create a record in table B. You can use following script in the business rule.

(function executeRule(current, previous /*null when async*/) {
    // Create a new GlideRecord for Table B
    var newRecord = new GlideRecord('table_b'); // Replace 'table_b' with the actual name of Table B.
    newRecord.initialize();

    // Copy fields from Table A to Table B
    newRecord.field1 = current.field1; // Replace 'field1' with the actual field names.
    newRecord.field2 = current.field2; // Add more fields as needed.

    // Insert the new record in Table B
    newRecord.insert();
})(current, previous);

 

Update the table and field name in the above business rule and use it to create record in table B.

 

Hope this helps.