Background Script: Query reference field to update another reference field

Desmo
Mega Guru

Hello Community,

Looking for help on a multi table query.

  1. Table 1 has a reference field, u_field_A
  2. Table 1 has a second reference field, u_field_B (Table 2)
  3. Table 2 has a reference field, u_field C (Table 3)
  4. If u_field_A is empty, then query u_field_B.u_field_C
  5. if u_field_C is not empty, update u_field_A with u_field_C.

Thank you,

Desmo

4 REPLIES 4

Aman Kumar S
Kilo Patron

What is the challenge here?

First of all your query is not very clear what exactly you are trying to achieve.

Also at least start with something, or you are looking for a ready-made solution for this?

 

Best Regards
Aman Kumar

Aman Kumar S
Kilo Patron

Here's something for reference:

10+ Tips for writing a quality community question

Best Regards
Aman Kumar

suvro
Mega Sage
Mega Sage

var gr = new  GlideRecord('table1');

gr.query();

while (gr.next()){

  if (gr.getValue(' u_field_A') == ''){

      if (gr.getValue('u_field_B.u_field_C')  != ''){

            gr.setValue('u_field_A', gr.getValue('u_field_B.u_field_C');

            gr.update();

     }

  }

}

Hi Suvro,

Line 10 had a missing closed parenthesis. Resolved error. After running the script, there were no results / total number of records updated. Simply shows "Script execution history and recovery available here".

 

var gr = new  GlideRecord('table1');

gr.query();

while (gr.next()){

  if (gr.getValue(' u_field_A') == ''){

      if (gr.getValue('u_field_B.u_field_C')  != ''){

            gr.setValue('u_field_A', gr.getValue('u_field_B.u_field_C'));

            gr.update();

     }

  }

}