
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 02:56 PM
Hi There,
I have a function in a business rule to convert the values from a list collector's sys_id to return them as string values to store in another table, but it is still return the sys_id values.
The business rule runs on the sc_req_item table - referencing the variable of the list collector: "lcMailboxes"
Using a GlideRecord to the other table "u_new_starter_templates" where the value is stored in column "u_shared_mailboxes"
My script is and I need to find out what I've missed to convert the values from sys_id to a string:
current.variables.lcMailboxes = convertListCollector();
function convertListCollector() {
var divArray = current.variables.lcMailboxes.toString().split(','); //split the list into an array
var outString = ''; //initialize clear the output string
for(i = 0; i < divArray.length; i++){ //Loop through List Collector Sys_ID array
var recObj = new GlideRecord('u_new_starter_templates'); //create table object
recObj.addQuery('sys_id',divArray[i]); //Create query to return record associated to Sys_ID
recObj.query(); //run the query
recObj.next();
var divValue = recObj.u_distribution_lists; //create variable with value from source field
if ( i == 0 ) {
outString = divValue; //don't start the string with a comma
} else {
outString = outString + ', ' + divValue; //append to output string variable
}
}
return outString;
}
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 03:00 PM
So you're receiving the sys_id because that's the value of a reference field. To get the actual "string" value you're referring to, that's the Display Value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 03:00 PM
So you're receiving the sys_id because that's the value of a reference field. To get the actual "string" value you're referring to, that's the Display Value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 05:02 PM
Thanks, would I change this line:
var divArray = current.variables.lcMailboxes.toString().split(',');
to var divArray = current.variables.lcMailboxes.togetDisplayValue().split(',');
I've tried it and had no luck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 04:32 PM
I dont think you can force a list collector to store a string instead of the sysid of the record list collector referencing to.
instead of current.variables.lcMailboxes = convertListCollector();, you should store the values returned in a separate variable or may be on a field on Requested Item which is string.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 11:19 PM
Hello,
Is u_distribution_lists a reference field, I think this is the reason why you get SYS_iDs back. You need to fetch the display value for u_distribution_lists
Replace these lines as below
var divValue = recObj.u_distribution_lists.getDisplayValue(); //create variable with value from source field
if ( i == 0 ) {
outString = divValue; //don't start the string with a comma
} else {
outString = outString + ', ' + divValue; //append to output string variable
}