Split returned variable from choice/select into 2 variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:24 PM
Hello,
In a Standard Catalog item I have added a choice question from a cmdb table. This choice returns the value from 2 columns in the cmdb table, separated by a vertical bar. But they are one single variable, I need to split these 2 values. Where can I do this? In Flow designer?
Thanks
Ron

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:40 PM
Hi Ron,
Values in a field can be split in Client Script.
For example, to split value from field named 'u_field1', create a onChange() or onSubmit() client script and use JavaScript's split() function.
e.g.
var valArray = g_form.getValue('u_field1").split('|'); // values will be in an array named valArray. First value will be in valArray[0] and second value will be in valArray[1].

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:46 PM
ServiceNow documents on Client Script and Business rules.
Client Script
Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:41 PM
Hi Ron,
Refer to thread: https://community.servicenow.com/community?id=community_question&sys_id=a16e4f80dbaa501011762183ca96...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:43 PM
Values may also be split in business rule before the data is entered into a database table.
Business rule also uses JavaScript so it'll still use the .split('\') function.
Where the script should be written will depend on how the split values will be used. If they are to be displayed on the form, create a client script. If they are to be saved to a database table fields, use business rule.