- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:27 PM
Hi All,
I have created a custom action as follows where everything is fine, I am getting the response in the execution details and status code as 200 but the data is not inserted in the custom table.
Here is my execution glimpse:
I am not sure why it is not inserting the data in the table.
Also, is script step the correct step? or I should use JSON parser step.
Kindly guide with the best practice.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 11:51 AM
@geet Can you try the following code and let me know if it works for you.
var jsonString = '{"data":[{"id":"rs-4ebd12446515b108","name":"jumpbox dev","tags":[787025,787027,787029],"typeAlias":"ssh","typeName":"ssh","hash":"a276a08591a55f2ae17718875d866b9e"},{"id":"rs-6d44ec9d651473a7","name":"dev cluster","tags":[787025,787026],"typeAlias":"aurora-postgres","typeName":"postgres","hash":"1236edc93afab533de3123eee4297d87"},{"id":"rs-771cc8536515b2b3","name":"jumpbox prod","tags":[787027,787028,787029],"typeAlias":"sshCert","typeName":"sshCert","hash":"8ddea064d0d8974698db7d6234f5a1bc"},{"id":"rs-7f69cf376504c5d5","name":"dogfood db","tags":[787025],"typeAlias":"postgres","typeName":"postgres","hash":"f0bece9698a2ac23a123ed477c637fa8"}],"totalCount":4,"pageInfo":{"cursor":null,"hasNextPage":false}}';
var jsonObj = JSON.parse(jsonString);
for (var i=0;i<jsonObj.data.length;i++) {
var id = jsonObj.data[i].id;
var name = jsonObj.data[i].name;
gs.info("ResID " +id);
gs.info("RESName " +name);
}
Hint: In your for loop you are running the loop upto the length of your JSON object whereas it should run upto the length of nested data object.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 11:51 AM
@geet Can you try the following code and let me know if it works for you.
var jsonString = '{"data":[{"id":"rs-4ebd12446515b108","name":"jumpbox dev","tags":[787025,787027,787029],"typeAlias":"ssh","typeName":"ssh","hash":"a276a08591a55f2ae17718875d866b9e"},{"id":"rs-6d44ec9d651473a7","name":"dev cluster","tags":[787025,787026],"typeAlias":"aurora-postgres","typeName":"postgres","hash":"1236edc93afab533de3123eee4297d87"},{"id":"rs-771cc8536515b2b3","name":"jumpbox prod","tags":[787027,787028,787029],"typeAlias":"sshCert","typeName":"sshCert","hash":"8ddea064d0d8974698db7d6234f5a1bc"},{"id":"rs-7f69cf376504c5d5","name":"dogfood db","tags":[787025],"typeAlias":"postgres","typeName":"postgres","hash":"f0bece9698a2ac23a123ed477c637fa8"}],"totalCount":4,"pageInfo":{"cursor":null,"hasNextPage":false}}';
var jsonObj = JSON.parse(jsonString);
for (var i=0;i<jsonObj.data.length;i++) {
var id = jsonObj.data[i].id;
var name = jsonObj.data[i].name;
gs.info("ResID " +id);
gs.info("RESName " +name);
}
Hint: In your for loop you are running the loop upto the length of your JSON object whereas it should run upto the length of nested data object.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 08:21 PM
@geet , @Sandeep Rajput has pointed out the issue for you 😀