How to convert array from using split() function to string

redth
Giga Expert

Hi, I need to refer to list collector variables from a catalog item in workflow. I have used split function to make the values comma separated and split function is returning the output in array. I need it in string type and used toString(), its not working and returned undefined. Please assist.

var Role = current.variables.u_roles.getDisplayValue().split(',');

workflow.scratchpad.removeRole = Role;        ---------> This the returns the output in array whereas I need it as string type

workflow.scratchpad.removeRole = Role.toString();     ---------> Returns undefined

 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

Not sure what your requirement is. If you split, you get an array. if you want to store the value as comma separated in a string, then do not split. use it directly like this.

workflow.scratchpad.removeRole =  current.variables.u_roles.getDisplayValue();

Mark the comment as a correct answer and helpful if this has answered the question.

View solution in original post

3 REPLIES 3

asifnoor
Kilo Patron

Hi,

Not sure what your requirement is. If you split, you get an array. if you want to store the value as comma separated in a string, then do not split. use it directly like this.

workflow.scratchpad.removeRole =  current.variables.u_roles.getDisplayValue();

Mark the comment as a correct answer and helpful if this has answered the question.

Aman Kumar S
Kilo Patron

Hey,

For list collector I don't think getDisplayValue() works. You will need to fetch the list, and then fetch the name by using GlideRecord for each list items.

Below article highlights the same:

Convert SysId Of List Collector to Display Value

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Chandu Telu
Tera Guru
Tera Guru

Hi,

Try @asifnoor code if it's doesn't workout if you want names you can use the below code

var xRole = current.variables.u_roles.getDisplayValue().split(',');

var xConvertString = '';

for(var i = 0; i < xRole.length; i++) {

var xRoleList = new GlideRecord('sys_user_role');

xRoleList.addQuery('sys_id', xRole[i]);
xRoleList.query();

while(xRoleList.next()){

xConvertString += xRoleList.name + ', '; - If You want names

}


}
gs.info("RoleName"+xConvertString)

 

Thanks
Chandu Telu
Please Mark ✅ Correct/helpful, if applicable,