Looping through all the fields from rest response
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 02:04 PM
I have a rest response of a few hundred records. I need to iterate through all and set the fields. Is there a way to loop through the rest api response and get the field names and set them? my table field values match the rest response field names.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 12:25 AM
Hi,
Please find the script to loop through all the keys and get the values. you can update it based on your requirement
var data = {"field1":"value1", "field2":"value2"}
for (var name in data) {
gs.info(data[name])
}
Thank you,
Palani
Palani
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 05:28 AM
Thank you, I tried it but getting only the first value
var data = response.allData[i];
for (var name in result){
gs.info(result[name]);
}
only returns first field.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 07:13 AM
You are using variable named data. So update the loop with correct variable name
var data = response.allData[i];
for (var name in data){
gs.info(data[name]);
}
Thank you,
Palani
Palani