- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 06:18 AM
Hi Team,
I have a requirement
I am using scripted rest API, the incoming payload like this ["Anil","Abeltuter","Androw"];
I want convert this to string and load List collector
help me on the same
AnilM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 07:05 AM
Hi,
You should be able to take the payload object and add: .toString() and then simply set your list collector to that value as it accepts a comma separated list anyway. Keep in mind that the list collector would need appropriate values, so if those names in your payload are actual values, then that's find, if not, and it's a reference to the sys_user table, for example, then you'd want to set the list collector to a comma separated list of sys_ids, instead, for example.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 07:05 AM
Hi,
You should be able to take the payload object and add: .toString() and then simply set your list collector to that value as it accepts a comma separated list anyway. Keep in mind that the list collector would need appropriate values, so if those names in your payload are actual values, then that's find, if not, and it's a reference to the sys_user table, for example, then you'd want to set the list collector to a comma separated list of sys_ids, instead, for example.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:51 AM
Hi @AnilM99 ,
I trust you are doing fine.
Here's one way you can accomplish this in ServiceNow:
First, you'll need to create a new Scripted REST API resource. Go to "System Web Services" > "Scripted REST APIs" and click on "New".
Give your new API a name and a relative path. For example, you could name it "ConvertToLC" and give it a relative path of "/convert-to-lc".
In the "Script" tab of your new API, you can write the code to handle the incoming payload. Here's an example script that converts the incoming array to a comma-separated string and loads it into a List collector:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Get the incoming payload from the request body
var payload = request.body.data;
// Convert the payload array to a comma-separated string
var payloadString = payload.join(',');
// Create a new List collector and set its value to the payload string
var lc = new GlideListCollector();
lc.setValue(payloadString);
// Return a success message and the List collector object
return {
message: 'Payload converted successfully',
lc: lc
};
})(request, response);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi