06-14-2024 03:05 AM
...
.map((elem, idx, arr) =>
{
"fieldA": elem.fieldA,
"fieldB": [
{
"fieldC1": elem.fieldC1,
"fieldC2": elem.fieldC2
},
{
"fieldD1": elem.fieldD1,
"fieldD2": elem.fieldD2
},
{
"fieldE1": elem.fieldE1,
"fieldE2": elem.fieldE2
}
]
}
)
...
...
{
"fieldC1": elem.fieldC1,
"fieldC2": elem.fieldC2
}, /* what about this "," (comma)? If D1 does not exist, then the comma should not be there.*/
(elem.fieldD1) ? "{ "fieldD1": elem.fieldD1, "fieldD2": elem.fieldD2 }," : ""
(elem.fieldE1) ? "{ "fieldE1": elem.fieldE1, "fieldE2": elem.fieldE2 }" : ""
...
Solved! Go to Solution.
06-14-2024 05:46 AM - edited 06-14-2024 09:41 AM
@adam_g - you were very close - try this
.map((elem, idx, arr) =>
{
"fieldA": elem.fieldA,
"fieldB": [
{
"fieldC1": elem.fieldC1,
"fieldC2": elem.fieldC2
}
]
.concat(
elem.get('fieldD1') > ''
? [
{
"fieldD1": elem.fieldD1,
"fieldD2": elem.fieldD2
}
]
: []
)
.concat(
elem.get('fieldE1') > ''
? [
{
"fieldE1": elem.fieldE1,
"fieldE2": elem.fieldE2
}
]
: []
)
}
)
Hope this helps!
06-14-2024 05:46 AM - edited 06-14-2024 09:41 AM
@adam_g - you were very close - try this
.map((elem, idx, arr) =>
{
"fieldA": elem.fieldA,
"fieldB": [
{
"fieldC1": elem.fieldC1,
"fieldC2": elem.fieldC2
}
]
.concat(
elem.get('fieldD1') > ''
? [
{
"fieldD1": elem.fieldD1,
"fieldD2": elem.fieldD2
}
]
: []
)
.concat(
elem.get('fieldE1') > ''
? [
{
"fieldE1": elem.fieldE1,
"fieldE2": elem.fieldE2
}
]
: []
)
}
)
Hope this helps!
06-14-2024 07:53 AM
Hi @koryknick,
Thank you again for replying!
Is there a way to check whether the value of elem.fieldD1 is null? The field elem.fieldD1 itself always exists, but the value is null sometimes. My bad for explaining it incorrectly.
I tried: elem.fieldD1 != null ? ...
But it did not work.
06-14-2024 09:41 AM
I updated my original reply to use Object.get() method; please test that result.
Hope this helps!