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

Rajdeep Ganguly
Mega Guru

The code you've mentioned is used to split a watch_list field into an array and then print each value. This is not directly related to GlideRecord but can be used in conjunction with it. Here's a breakdown: - current.watch_list.getDisplayValue(); This line is getting the display value of the 'watch_list' field from the current record. The 'current' object represents the current record in ServiceNow. - var array = list.split(","); This line is splitting the 'list' variable (which holds the watch_list field value) into an array. The split function splits a string into an array of substrings based on a specified delimiter, in this case, a comma. - The for loop is then iterating over each element in the array and printing it out using gs.print. Here's how you might use this in conjunction with GlideRecord: 1. Create a new GlideRecord object for the table you're interested in. 2. Use the .get() method to retrieve a specific record. 3. Use the code you've provided to split the watch_list field and print each value. Example: javascript var gr = new GlideRecord('incident'); if (gr.get('sys_id', 'your_sys_id_here')) { var list = gr.watch_list.getDisplayValue(); var array = list.split(","); for (var i=0; i < array.length; i++) { gs.print("Display value is: " + array[i]); } } In this example, replace 'your_sys_id_here' with the sys_id of the record you're interested in. This code will print out each value in the watch_list field of that record.