how to compare 2 different fields on 2 different tables after comparing data is not same copy the data into table1 differet section.

padhu1
Kilo Expert

I have Table1 and table 2 :

                                                                          I need to compare 2 different fields on 2 different tables and   we have common id field on 2 tables like(reg id) and

(if img data !=sdpe data, copy the "img data"(section in table1) to "upd   data"(another section in table1)

Note:img data is (table1 field),   sdpe is (table2 field).

any one give the sample code for this req.

is this clear.if not please comment it.

Thanks in Advance.

Message was edited by: padhu1 padhu1

1 ACCEPTED SOLUTION


Amlan pal,


                                        Thanks for the quick reply.


how will pass the section name here? once


(if img data !=sdpe data,copy the "img data"(section in table1) to "upd   data"(another section in table1).how to copy the data?




View solution in original post

7 REPLIES 7

amlanpal
Kilo Sage

Hi Padhu,



You may write Business rule as per sample script as below. Define the Business rule when to run.



var img_value = current.img_data_field_name;


var id = current.reg_id;


var field1 = current.field_1_name; //fetch the value of 1st field name which will be compared with the 2nd field in 2nd table.


var gr= new GlideRecord('2nd_table_name');


gr.addQuery('reg_id', id);


gr.addQuery('field_2_name', '!=', field1);


gr.queary();


if (gr.next()) {


gr.fiield_2_name = field1;


gr.update();


}



I hope this helps.Please mark correct/helpful based on impact



Amlan pal,


                                        Thanks for the quick reply.


how will pass the section name here? once


(if img data !=sdpe data,copy the "img data"(section in table1) to "upd   data"(another section in table1).how to copy the data?




Hi Padhu,



If your requirement is to copy all the fields value from a section then mention the field name one by one inside the if() loop as:


if (gr.next()) {


gr.fiield_2_name = field1;


gr.new_field_name1 = current.source_field_name1;


gr.new_field_name2 = current.source_field_name2;


gr.new_field_name3 = current.source_field_name3;


gr.update();


}



I hope this helps.Please mark correct/helpful based on impact


Hi Amlan Pal,


until this code working fine .below line of code is not working.can u please review this?


  gr.fiield_2_name = field1;


  gr.update();




Thanks in Advance.