The CreatorCon Call for Content is officially open! Get started here.

Business rule with function to convert list collector sys_ids to string in another table

Anna Gausel
Giga Expert

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;
	
}
1 ACCEPTED SOLUTION

Coleton
Kilo Guru

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.

View solution in original post

6 REPLIES 6

manish64
Giga Guru

use getDisplayValue() instead of toString()

Anna Gausel
Giga Expert

Thanks all, I've got it working using getDisplayValue()