问题
I have to read data from an XML and load it to SQL. So in middle I need to add some business logic for each record for which I used for each task in Logic Apps. But when there is a single record in the XML, result is being considered as Object rather than array and logic app fails
This is how my XML looks:
<VDSP_INPUT_A_Set><VDSP_INPUT_A_Record><head><blanket_number>CMC741311</blanket_number></head></VDSP_INPUT_A_Record></VDSP_INPUT_A_Set>
ForEach logic: VDSP_INPUT_A_Set.VDSP_INPUT_A_Record
Foreach loop needs to executed even if there is one record in XML
回答1:
For this issue, I did some research. I convert the xml to json, while there is only one record under , the result json will be {key/value pair} but not [array]. So if we fill in For each with this value, the action will fail. I think this issue caused by design.
For a workaround, I think we can add a specific record under , for example:
<VDSP_INPUT_A_Set>
<VDSP_INPUT_A_Record>
<head>
<blanket_number>CMC741311</blanket_number>
</head>
<head>
<blanket_number>specific_test</blanket_number>
</head>
</VDSP_INPUT_A_Record>
</VDSP_INPUT_A_Set>
And then add a condition(If) action in For each action to determine if it is equal to "specific_test".
If true: do insert sql
If false: do nothing
来源:https://stackoverflow.com/questions/57457429/foreach-not-supporting-when-the-result-set-has-one-record-in-logic-apps