Get values ​​from an array in Json format

marioalberto
Kilo Contributor

Hello everyone,

I have the requirement to extract SOAP response data, which is:

find_real_file.png

For which I have built the following to get just the Json format:

find_real_file.png

Obtaining the following result and without seeing the values ​​of the array

find_real_file.png

If any of you can tell me why that happens by passing it to a json object and how can I get only PrinterDeviceID 3, 6, 7 and 9 records?

I appreciate your help, regards.

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Replace gs.log() statement with the following script.

for (var i = 0; i<obj.length; i++) {
	gs.log(obj[i].SupplyChangeID + ',' + obj[i].PrinterDeviceID);
}

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

This is happening because you're parsing the data in "Execute Result" which JSON.parse is turning into an array of objects. You'll need to iterate over the array using a for loop to extract data. You can then use a nested if statement to only run whatever logic you want when the PrinterDeviceID is equal to 3,6,7,9

Hello Kieran, your help has helped me a lot.

I thank you and wish the best.

Hitoshi Ozawa
Giga Sage
Giga Sage

Replace gs.log() statement with the following script.

for (var i = 0; i<obj.length; i++) {
	gs.log(obj[i].SupplyChangeID + ',' + obj[i].PrinterDeviceID);
}

Hello Kieran, your help has been very useful to me to correctly extract the information I need.

I thank you and send greetings.