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

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.

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.

SanjivMeher
Kilo Patron
Kilo Patron

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.

Alikutty A
Tera Sage

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
		}