How to populate GlideList values as text in string field?

GUNDIGI POOJIT1
Tera Contributor

How can we get text from glidelist and populate that in the string field? Is it possible through GlideAjax and script include? If Yes, Please suggest me the solution.

1 ACCEPTED SOLUTION

GLewis5
Tera Guru

A glidelist contains a comma separated list of sys_ids. 

In this server javascript, value is the value of the glidelist and tablename is the name of the referenced table. The procedure is

  1. Split the glidelist into an array
  2. Look up each of those sys_id values in the referenced table
  3. Get the display value and push it onto a new array
  4. Join the display values together and return as a string
var listSysID = value.toString().split(',');
var listDisplay = [];
for (var i = 0; i < listSysID.length; ++i) {
var grRef = new GlideRecord(tablename);
grRef.get(listSysID[i]);
listDisplay.push(grRef.getDisplayValue());
}
var result = listDisplay.join(',');

View solution in original post

1 REPLY 1

GLewis5
Tera Guru

A glidelist contains a comma separated list of sys_ids. 

In this server javascript, value is the value of the glidelist and tablename is the name of the referenced table. The procedure is

  1. Split the glidelist into an array
  2. Look up each of those sys_id values in the referenced table
  3. Get the display value and push it onto a new array
  4. Join the display values together and return as a string
var listSysID = value.toString().split(',');
var listDisplay = [];
for (var i = 0; i < listSysID.length; ++i) {
var grRef = new GlideRecord(tablename);
grRef.get(listSysID[i]);
listDisplay.push(grRef.getDisplayValue());
}
var result = listDisplay.join(',');