How Can we use " getDisplayValue()" in GlideRecord()

Kishore8
Kilo Guru

Plse friends don't give your replay with below mentioned code

var list = current.watch_list.getDisplayValue();

  var array = list.split(",");

  for (var i=0; i < array.length; i++) {

    gs.print("Display value is: " + array[i]);

  }

i am learner so plse explain , i want to know where we use, how we use   in GlideRecord..............

5 REPLIES 5

amlanpal
Kilo Sage

Hi Kishore,



Please find the modified code below. I hope this is what you are looking for.



var list = current.watch_list;


  var array = list.toString().split(",");


  for (var i=0; i < array.length; i++) {


    gs.print("Display value is: " + array[i]);


  }



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


Harsh Vardhan
Giga Patron

Hi



Please check the link below. section 5.5



Coding Best Practices - ServiceNow Wiki  



Thanks,


Harshvardhan


The SN Nerd
Giga Sage
Giga Sage

GlideRecord getDisplayValue()


https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_GlideRecord-getDisplayValue



var gr = new GlideRecord('incident');


gr.initialize();


gs.print(gr.getDisplayValue());



INC1000010




GlideElement getDisplayValue()


https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_GlideElement-getDisplayValue_Numbe...



var fields = current.getFields();
for (var i = 0; i < fields.size(); i++) {
  var field = fields.get(i);
  var name = field.getName();
  var value = field.getDisplayValue();
  gs.print(i + ". " + name + "=" + value);
}

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Chuck Tomasi
Tera Patron

If your objective in this case is to identify the user's associated with the watch_list, then this will do it:



BTW, avoid calling arrays 'array'. (Or any other data type)



var watch_list = current.getValue('watch_list'); // get the comma separated sys_ids


  var list = watch_list.split(","); store it in an array


  for (var i=0; i < list.length; i++) {


        var user = new GlideRecord('sys_user');


        user.get(list[i]);


        gs.print("Display value is: " + user.getDisplayValue());


  }