Updating Reference Field

kailashthiyagar
Kilo Guru

I would like to update a reference field but the value is not getting saved. Here md5hash is a reference field. And the value which I m assigning is not a sysid but it's the actual MD5hash value of sample file. Reference is not getting added to the table. I tried updating other columns inside the while loop and it works fine.

I tried few other things but nothing worked

  1. macFileNameRec.md5hash='sysid'
  2. macFileNameRec.md5hash.setDisplayValue(''4E93C1EA01B65497AEB9BA0C7F7457AA');

                              var macFileNameRec=new GlideRecord('x_opt_macro_govern_macro_file_names');

                                                              macFileNameRec.addQuery('file_name',fileName);

                                                              macFileNameRec.query();

                                                              if(macFileNameRec.hasNext()){

                                                                                              while(macFileNameRec.next()){

                                                                                                                              macFileNameRec.md5hash='4E93C1EA01B65497AEB9BA0C7F7457AA';

                                                                                                                              macFileNameRec.update();

                                                                                                                             

                                                                                              }

                                                              }

1 ACCEPTED SOLUTION

Is md5hash field referencing a table?



If yes, you can query the table and then assign the sys_id to the reference field. Something like this.



var macFileNameRec=new GlideRecord('x_opt_macro_govern_macro_file_names');


                                                              macFileNameRec.addQuery('file_name',fileName);


                                                              macFileNameRec.query();


                                                              if(macFileNameRec.hasNext()){


                                                                                              while(macFileNameRec.next()){


                                                                                                                                var md = new GlideRecord('md5 table name');


                                                                                                                                md.addQuery('field value','4E93C1EA01B65497AEB9BA0C7F7457AA');


                                                                                                                                md.query();



                                                                                                                              if (md.next())


                                                                                                                              {


                                                                                                                              macFileNameRec.md5hash=md.sys_id;


                                                                                                                              macFileNameRec.update();


                                                                                                                                }


                                                                                                                           


                                                                                              }


                                                              }



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

7 REPLIES 7

Is md5hash field referencing a table?



If yes, you can query the table and then assign the sys_id to the reference field. Something like this.



var macFileNameRec=new GlideRecord('x_opt_macro_govern_macro_file_names');


                                                              macFileNameRec.addQuery('file_name',fileName);


                                                              macFileNameRec.query();


                                                              if(macFileNameRec.hasNext()){


                                                                                              while(macFileNameRec.next()){


                                                                                                                                var md = new GlideRecord('md5 table name');


                                                                                                                                md.addQuery('field value','4E93C1EA01B65497AEB9BA0C7F7457AA');


                                                                                                                                md.query();



                                                                                                                              if (md.next())


                                                                                                                              {


                                                                                                                              macFileNameRec.md5hash=md.sys_id;


                                                                                                                              macFileNameRec.update();


                                                                                                                                }


                                                                                                                           


                                                                                              }


                                                              }



Please mark this response as correct or helpful if it assisted you with your question.

Thanks sanjivmeher .. it worked.. i tried that approach before but for some reason it didnt work...


setDisplayValue worked for me thanks!!