AngularJS convert String to Array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2018 05:18 AM
Hello All,
I am accessing some data from a table in a service portal widget. One of the fields being returned is a string field that contains the following data:
ACS_ADMIN_USER, CUST_ESIGN_URL, SALES_USER, RETAIL
In this field there are 4 'Roles' that are comma separated.
I want the portal widget to display this field as:
ACS_ADMIN_USER
CUST_ESIGN_URL
SALES_USER
RETAIL
I would like to do this without any modification on the field itself as this data is used elsewhere.
Is there an easy way to achieve this? This is being displayed on the widget using: {{data.string.u_role}}
This is the Server Script that gets the data:
var Role = GlideRecord('u_services_roles_users');
Role.get(locSysId);
data.string = {};
$sp.getRecordDisplayValues(data.string, Role, 'u_role');
Any help would be greatly appreciated.
Thanks
Harry
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2018 09:43 AM
What you're looking for is the JavaScript "split" method.
var array = data.string.u_role.split(", ");
Is there a reason you're using getRecordDisplayValues() instead of getDisplayValue() since you're only getting a single field. It's also confusing because you're setting "data.string" to an object and not a string.
Nathan Firth
Founder and ServiceNow Architect
NewRocket, Inc.
nathan.firth@newrocket.com
http://serviceportal.io
http://newrocket.com