Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

union() expression function in logic app returning string instead of collection #6419

Open
asos-chrisnorman opened this issue Jan 17, 2025 · 0 comments

Comments

@asos-chrisnorman
Copy link

asos-chrisnorman commented Jan 17, 2025

Describe the Bug with repro steps

In a Logic App Standard workflow in a foreach condition, we are using a union expression function to union a collection with itself, in order to removed duplicates and get an array of distinct elements.

The reference guide states the union function returns an "Array or Object, respectively", but we are receiving the following error:

ExpressionEvaluationFailed

The execution of template action 'For_each_scenario' failed: the result of the evaluation of 'foreach' expression '@{union(body('Select_scenario_names_from_CSV'), body('Select_scenario_names_from_CSV'))}' is of type 'String'. The result must be a valid array.

What type of Logic App Is this happening in?

Standard (Portal)

Which operating system are you using?

Windows

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_CSV_JSON_data": {
                "inputs": {
                    "from": "@skip(outputs('Split_Lines'), 1)",
                    "select": {
                        "@{outputs('Split_Field_Names')[0]}": "@split(item(), ',')?[0]",
                        "@{outputs('Split_Field_Names')[1]}": "@split(item(), ',')?[1]",
                        "@{outputs('Split_Field_Names')[10]}": "@split(item(), ',')?[10]",
                        "@{outputs('Split_Field_Names')[11]}": "@split(item(), ',')?[11]",
                        "@{outputs('Split_Field_Names')[12]}": "@split(item(), ',')?[12]",
                        "@{outputs('Split_Field_Names')[13]}": "@split(item(), ',')?[13]",
                        "@{outputs('Split_Field_Names')[14]}": "@split(item(), ',')?[14]",
                        "@{outputs('Split_Field_Names')[2]}": "@split(item(), ',')?[2]",
                        "@{outputs('Split_Field_Names')[3]}": "@split(item(), ',')?[3]",
                        "@{outputs('Split_Field_Names')[4]}": "@split(item(), ',')?[4]",
                        "@{outputs('Split_Field_Names')[5]}": "@split(item(), ',')?[5]",
                        "@{outputs('Split_Field_Names')[6]}": "@split(item(), ',')?[6]",
                        "@{outputs('Split_Field_Names')[7]}": "@split(item(), ',')?[7]",
                        "@{outputs('Split_Field_Names')[8]}": "@split(item(), ',')?[8]",
                        "@{outputs('Split_Field_Names')[9]}": "@split(item(), ',')?[9]"
                    }
                },
                "runAfter": {
                    "Split_Field_Names": [
                        "SUCCEEDED"
                    ]
                },
                "type": "Select"
            },
            "For_each_scenario": {
                "actions": {
                    "Check_if_ASN_required": {
                        "actions": {
                            "Append_to_Links_array_(With_ASN)": {
                                "inputs": {
                                    "name": "Links",
                                    "value": "https://edi-@{parameters('environmentCode')}.asosdevelopment.com/edi/integration-test/@{replace(toLower(body('Filter_CSV_array_for_scenario')[0]?['Brand Partner Name']),'''','')}_@{item()?['Scenario']}_@{body('Invoke_po-and-asn-incrementer-workflow')?['PoNumber']}_@{body('Invoke_po-and-asn-incrementer-workflow')?['AsnNumber']}"
                                },
                                "runAfter": {
                                    "Upload_ASN_to_storage_container_": [
                                        "SUCCEEDED"
                                    ]
                                },
                                "type": "AppendToArrayVariable"
                            },
                            "Create_ASN": {
                                "inputs": {
                                    "AdvancedShipmentCreateNotification": {
                                        "ASNInDesc": {
                                            "asn_nbr": "@body('Invoke_po-and-asn-incrementer-workflow')?['AsnNumber']",
                                            "ASNInPO": [
                                                {
                                                    "ASNInItem": [
                                                        {
                                                            "final_location": "@body('Filter_CSV_array_for_scenario')[0]?['Warehouse Storage Location (ASOS Final FC Location)']"
                                                        }
                                                    ],
                                                    "po_nbr": "@body('Invoke_po-and-asn-incrementer-workflow')?['PoNumber']"
                                                }
                                            ],
                                            "vendor_nbr": "@body('Invoke_po-detail-construction-workflow')?['skuData']?['SupplierId']"
                                        }
                                    }
                                },
                                "type": "Compose"
                            },
                            "Upload_ASN_to_storage_container_": {
                                "inputs": {
                                    "parameters": {
                                        "blobName": "@{replace(toLower(body('Filter_CSV_array_for_scenario')[0]?['Brand Partner Name']),'''','')}/asns/@{body('Filter_CSV_array_for_scenario')[0]?['Scenario']}_ASN_@{body('Invoke_po-and-asn-incrementer-workflow')?['AsnNumber']}.json",
                                        "containerName": "test-data",
                                        "content": "@outputs('Create_Asn')",
                                        "overrideIfExists": "true"
                                    },
                                    "serviceProviderConfiguration": {
                                        "connectionName": "AzureBlob",
                                        "operationId": "uploadBlob",
                                        "serviceProviderId": "/serviceProviders/AzureBlob"
                                    }
                                },
                                "runAfter": {
                                    "Create_ASN": [
                                        "SUCCEEDED"
                                    ]
                                },
                                "type": "ServiceProvider"
                            }
                        },
                        "else": {
                            "actions": {
                                "Append_to_Links_array_(Without_ASN)": {
                                    "inputs": {
                                        "name": "Links",
                                        "value": "https://edi-@{parameters('environmentCode')}.asosdevelopment.com/edi/integration-test/@{replace(toLower(body('Filter_CSV_array_for_scenario')[0]?['Brand Partner Name']),'''','')}_@{item()?['Scenario']}_@{body('Invoke_po-and-asn-incrementer-workflow')?['PoNumber']}"
                                    },
                                    "type": "AppendToArrayVariable"
                                }
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "equals": [
                                        "@body('Filter_CSV_array_for_scenario')[0]?['ASN Required']",
                                        "Y"
                                    ]
                                }
                            ]
                        },
                        "runAfter": {
                            "Upload_purchaseorder_to_storage_container": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "If"
                    },
                    "Create_Purchase_Order": {
                        "inputs": {
                            "ApprovalDate": "@utcNow()",
                            "BuyingGroupID": "@body('Invoke_po-detail-construction-workflow')?['skuData']?['buyingGroupId']",
                            "BuyingGroupName": "@body('Invoke_po-detail-construction-workflow')?['skuData']?['buyingGroup']",
                            "CurrencyCode": "@body('Filter_CSV_array_for_scenario')[0]?['PO Currency']",
                            "ExpectedDeliveryDateFirstLocation": "@body('Filter_CSV_array_for_scenario')[0]?['Requested Delivery Date']",
                            "ExpectedHandoverDate": "@body('Filter_CSV_array_for_scenario')[0]?['Requested Delivery Date']",
                            "FreightForwarder": "@body('Filter_CSV_array_for_scenario')[0]?['Delivery Party (ASOS Carrier)']",
                            "HandoverWindowEndDate": "@body('Filter_CSV_array_for_scenario')[0]?['Latest Delivery Date']",
                            "HandoverWindowStartDate": "@body('Filter_CSV_array_for_scenario')[0]?['Earliest Delivery Date']",
                            "LastUpdateDateTime": "@utcNow()",
                            "OrderNo": "@body('Invoke_po-and-asn-incrementer-workflow')?['PoNumber']",
                            "PODtl": "@body('Invoke_po-detail-construction-workflow')?['purchaseOrderDetails']",
                            "SupplierConfirmation": "Y",
                            "SupplierID": "@body('Invoke_po-detail-construction-workflow')?['skuData']?['SupplierId']",
                            "SupplierName": "@body('Invoke_po-detail-construction-workflow')?['skuData']?['SupplierName']"
                        },
                        "runAfter": {
                            "Invoke_po-and-asn-incrementer-workflow": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "Compose"
                    },
                    "Filter_CSV_array_for_scenario": {
                        "inputs": {
                            "from": "@body('Create_CSV_JSON_data')",
                            "where": "@equals(item()?['Scenario'],items('For_each_scenario')?['Scenario'])"
                        },
                        "type": "Query"
                    },
                    "Invoke_po-and-asn-incrementer-workflow": {
                        "inputs": {
                            "host": {
                                "workflow": {
                                    "id": "po-and-asn-incrementer-workflow"
                                }
                            }
                        },
                        "runAfter": {
                            "Invoke_po-detail-construction-workflow": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "Workflow"
                    },
                    "Invoke_po-detail-construction-workflow": {
                        "inputs": {
                            "body": "@body('Filter_CSV_array_for_scenario')",
                            "headers": {
                                "brandPartnerName": "@{replace(toLower(body('Filter_CSV_array_for_scenario')[0]?['Brand Partner Name']),'''','')}"
                            },
                            "host": {
                                "workflow": {
                                    "id": "po-detail-construction-workflow"
                                }
                            }
                        },
                        "runAfter": {
                            "Filter_CSV_array_for_scenario": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "Workflow"
                    },
                    "Upload_purchaseorder_to_storage_container": {
                        "inputs": {
                            "parameters": {
                                "blobName": "@{replace(toLower(body('Filter_CSV_array_for_scenario')[0]?['Brand Partner Name']),'''','')}/purchase-orders/@{body('Filter_CSV_array_for_scenario')[0]?['Scenario']}_PO_@{outputs('Create_Purchase_Order')?['OrderNo']}.json",
                                "containerName": "test-data",
                                "content": "@outputs('Create_Purchase_Order')",
                                "overrideIfExists": "true"
                            },
                            "serviceProviderConfiguration": {
                                "connectionName": "AzureBlob",
                                "operationId": "uploadBlob",
                                "serviceProviderId": "/serviceProviders/AzureBlob"
                            }
                        },
                        "runAfter": {
                            "Create_Purchase_Order": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "ServiceProvider"
                    }
                },
                "foreach": "@{union(body('Select_scenario_names_from_CSV'), body('Select_scenario_names_from_CSV'))}",
                "runAfter": {
                    "Initialise_Links_array_variable": [
                        "SUCCEEDED"
                    ]
                },
                "runtimeConfiguration": {
                    "concurrency": {
                        "repetitions": 1
                    }
                },
                "type": "Foreach"
            },
            "Select_scenario_names_from_CSV": {
                "inputs": {
                    "from": "@body('Create_CSV_JSON_data')",
                    "select": {
                        "Scenario": "@item()?['Scenario']"
                    }
                },
                "runAfter": {
                    "Create_CSV_JSON_data": [
                        "SUCCEEDED"
                    ]
                },
                "type": "Select"
            },
            "Initialise_Links_array_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Links",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Select_scenario_names_from_CSV": [
                        "SUCCEEDED"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Response": {
                "inputs": {
                    "body": "@variables('Links')",
                    "statusCode": 200
                },
                "kind": "Http",
                "runAfter": {
                    "For_each_scenario": [
                        "SUCCEEDED"
                    ]
                },
                "type": "Response"
            },
            "Split_Field_Names": {
                "inputs": "@split(first(outputs('Split_Lines')), ',')",
                "runAfter": {
                    "Split_Lines": [
                        "SUCCEEDED"
                    ]
                },
                "type": "Compose"
            },
            "Split_Lines": {
                "inputs": "@split(triggerBody(),decodeUriComponent('%0D%0A'))",
                "runAfter": {},
                "type": "Compose"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "kind": "Stateful"
}

Screenshots or Videos

Image

Image

Image

Browser

Edge

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant