How to convert this string to an array in ServiceNow server side script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2023 11:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2023 12:45 AM
To convert a string to an array in ServiceNow server-side script, you can use the split() method. The split() method splits a string into an array of substrings based on a specified separator.
Here's an example code snippet that demonstrates how to convert a string to an array using the split() method in ServiceNow server-side script:
In this example, the string "apple,banana,orange" is split into an array of three elements using the comma (",") separator. The resulting array will look like this:
You can adjust the separator parameter of the split() method to fit your specific use case...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2023 04:36 AM
Hi Snehal,
To convert a comma-separated string to an array in ServiceNow server-side script, you can use the split() method. Here's an example script:
var csvString = "apple,banana,orange";
var myArray = csvString.split(",");
// Now myArray contains ["apple", "banana", "orange"]
In this example, the split() method is called on the csvString variable with a comma as the separator argument. This returns an array of strings that are separated by commas in the original string. The resulting array is assigned to the myArray variable.
You can replace the csvString variable with the string you want to convert to an array in your ServiceNow server-side script.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 01:55 AM
Hi Snehal,
Please accept the solution. If it's working for you.
Thanks,
Rahul Kumar