GlideRecord get label of reference field instead of sys_id

Tadz
Tera Guru
Tera Guru

Hi, is there a way to get the label of the reference field from GlideRecord. instead of sys_id?

Here are some screenshots:

                  Specifications: u_topic field is referenced from another table.

q2.PNG

q1.png

9 REPLIES 9

Hi Rober, I have tried your suggestion but I think it doesn't work on gliderecord.


Also this is in a catalog item.



Thanks,



Tadz


Cris,



You need to use value and display value.


You can refer this example:


GlideForm (g form) - ServiceNow Wiki



In your case it will be:


g_form.addOption('u_topic', value of topic, label of topic);




PS: Hit like, Helpful or Correct depending on the impact of the response.


Hi Mishra,



I'm trying to make the options dynamic, thats why i use gliderecord.


My problem is I can't get the label of the topic. It only fetch the sys_id value of it since it is referenced



Thanks,



Tadz


zica
Giga Guru

Hi Thadeo,



You have to use GLide Ajax, Here is a sample that I have developed to get the work notes value (I dont have the same field than you and you can use it as your requierement, Dont forget to change the value of the field) .


TO achieve this, you have to first create a script include   :



Script include :


name : worknotesMandatory


Client Callable : true


Script :


var worknotesMandatory = Class.create();


worknotesMandatory.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  worknotes: function() {


  var worknotes = this.getParameter('sysparm_current_worknotes');


  if (worknotes == '') {


            return this.getParameter('sysparm_current_worknotes');


  }


  }


});



One note : in your case here, you can copy and paste you glideRecord. And you can return gr.fieldName.getDisplayValue() to get display Value of the field (examle : gr.u_topic.getDisplayValue())




Then a client script which will call the script include above :


function onLoad() {


    //Type appropriate comment here, and begin script below


    makeWkMandatory();


}



That is all,




Let me know if you need more helps, I believe that will help to clear your issue:



Kind regards,


ZA


Do not feel shy to mark correct or helpful answer if it helps or is correct


Hi Zic,



Right now, Im working on it.
Will tell you later if I have issues or it works.



Thanks



Tadz