Flow Designer - Custom Action to Parse the JSON response and insert in custom Table

geet
Tera Guru

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.

geet_0-1695943540151.png

Here is my execution glimpse:

geet_1-1695943580150.png


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.

1 ACCEPTED SOLUTION

@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.

View solution in original post

6 REPLIES 6

@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.

@geet , @Sandeep Rajput  has pointed out the issue for you ðŸ˜€