Need Script to take values from different table using business rule

malaisamy1
Kilo Contributor

Hi Team,

I have been gone through many codes. but i am not able to resolve this issue.

Can someone help me on this,

My scenario is,

i have two tables consider, Table A and Table B. I need to take some values from Table A to Table B by some condition.

Condition : If Table A   fields slid_sla and met_num, rep_mon is matching with the Table B fields sl_ids,sla_reference_number,approval_date then it has to take the sl_type field value and to store in approval field.

I have tried the below code in 'Table B' ,

var mon1 = new GlideRecord('Table A');

mon1.addQuery('slid_sla',current.sl_ids);

  var temp1 =   mon1.addQuery('met_num',current.sla_reference_number);

  temp1.addCondition('rep_mon',current.approval_date);

  mon1.addQuery();

  if(mon1.next())

  current.approval = mon1.sl_type;

    current.update();

i am not getting the result. May i know where i struck?

One more issue with this code is if the condition is not matching then its creating a duplicate empty record in Table A.

Can someone help me on this?

Thanks in Advance,

Malaisamy J

1 ACCEPTED SOLUTION

priyanka154
Mega Expert

Hi Malaisamy,



Can you try this code, and let me know



var mon1=new GlideRecord('TableA');


mon1.addQuery('slid_sla',current.sl_ids);


mon1.addQuery('met_num',current.sla_reference_number);


mon1.addQuery('rep_mon',current.approval_date);


mon1.query();


if(mon1.next())


{


current.approval=mon1.sl_type;


}



Hit Like/Helpful/Correct based on the impact!



Thanks,


Priyanka


View solution in original post

3 REPLIES 3

priyanka154
Mega Expert

Hi Malaisamy,



Can you try this code, and let me know



var mon1=new GlideRecord('TableA');


mon1.addQuery('slid_sla',current.sl_ids);


mon1.addQuery('met_num',current.sla_reference_number);


mon1.addQuery('rep_mon',current.approval_date);


mon1.query();


if(mon1.next())


{


current.approval=mon1.sl_type;


}



Hit Like/Helpful/Correct based on the impact!



Thanks,


Priyanka


malaisamy1
Kilo Contributor

Hi Priyanka,



I have tried the above code its not working..Is there anyother way to achieve?




Thanks,



Malaisamy


Hi Malaisamy,



Is your issue resolved? Could you please put logs or InfoMessages to see where exactly are you stuck? The code provided by Priyanka should work.



Regards,


Prajakta



PS - Hit Like, Helpful or Correct based on the impact of the response.