- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:51 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:56 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:56 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:59 AM
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 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 10:12 AM
Hi,
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,