Error when 1 object in array

Hi!

We get an XML respond from our ERP, when we make an API call. We use the Item Lists (splitOutItems) module to iterate the arrays we get. It is works like charm.

However in some cases the answer array only contains 1 object. At that case the Item Lists Node got an error, becouse it is not an array.

The parsed json:

[
{
"vissza": {
"hiba": "0",
"valasz": {
"elem": {
"sorszam": "R22/00083",
"statusz": "N",
"torolt": "0",
"fej": {
"kelt": "2022.05.20",
"valuta": "HUF",
"arfolyam": "1",
"part_kod": "36",
"afaval": "HUN",
"megjegyzes": "",
"nyelv": ""
},
"tetelek": {
"tetel": {
"azon": "225",
"cikksz": "32670-AA0100",
"netto_ar": "0",
"menny": "1",
"tmegjegy": "{ Előlapi fénykép: Hátlapi szöveg: Hátlapi fénykép: https://www.gravirgyar.hu/wp-content/uploads/extra_product_options/e48b0dd9fe55b6248d241fe5b999b9de/1DEDA7C1-BB94-4BEE-8A59-9CED8227EC93.jpeg Egyedi üzenet: }",
"menny_info": {
"beszerzett": "0",
"teljnek_vett": "0"
}
}
}
}
}
}
}
]

The error:

Is there any workaround to handle the situation when there will be only one object?

Thank you!

Describe the issue/error/question

What is the error message (if any)?

Problem executing workflow

There was a problem executing the workflow:
"Item Lists2: The provided field ‘vissza.valasz.elem.tetelek.tetel’ is not an array"

Hey @Temco,

What about using an if node first to check the length of if it is an array and if isn’t skip the item list node if it is go through it?

I thinked about that, unfortunately my coding skill is almost zero, and I couldn’t make it work with the length function.

Hi @Temco

I had this issue once aswell.
try using [].concat(yourfield) to force the array

3 Likes

That is a nice solution.

Can’t take the credits though. I asked the same question on the community and got the same answer. :slight_smile:

Thank you!

Just found your original post! :slight_smile:

2 Likes