0

I'm newbie into Logic App. And I'm really struggling with some basics of it, especially when it comes to manipulation/selecting of data.

I have a problem with checking if key is present in collection.

I have this variable:

"Initialize_ReportType_Variable": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "ReportTypeCollection",
                            "type": "Array",
                            "value": "@parameters('reportType')"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_GAIMFunds": [
                        "SUCCEEDED"
                    ]
                }
            }

It returns an output of array:

[
  {
    "FundKey": "1",
    "FundName": "s1",
    "ReportGroup": "A",
    "StoredProcedure": "SP_1"
  },
  {
    "FundKey": "2",
    "FundName": "s2",
    "ReportGroup": "B",
    "StoredProcedure": "SP_2"
  }
]

Then there are like output of variable Process_Filtered_Output:

{
  "FilteredResults": [
    {
      "ProcessID": 1,
      "ProcessName": "A1",
      "ImportID": 1,
      "ImportName": "I1",
      "WorkspaceName": "A",
      "WorkspaceID": "8a",
      "ModelID": "58B4",
      "ModelName": "M1",
      "ReportType": 1
    }
  ]
}

I just need to check if there is an ReportType = FundKey in Initialize_ReportType_Variable by Process_Filtered_Output.ReportType.

Please help me to figure out how can it be resolved.

I've tried with bunch of approaches like For_Each, but I can't even to write it normal without errors.

1
  • Are you getting any error while using this approach? Commented Dec 4, 2024 at 3:32

1 Answer 1

0

I have used the below given workflow to get the results by comparing FundKey with ReportType using Filter array.

enter image description here

enter image description here

Code:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "ReportTypeCollection": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "ReportTypeCollection",
                            "type": "array",
                            "value": [
                                {
                                    "FundKey": "1",
                                    "FundName": "s1",
                                    "ReportGroup": "A",
                                    "StoredProcedure": "SP_1"
                                },
                                {
                                    "FundKey": "2",
                                    "FundName": "s2",
                                    "ReportGroup": "B",
                                    "StoredProcedure": "SP_2"
                                }
                            ]
                        }
                    ]
                },
                "runAfter": {}
            },
            "Process_Filtered_Output": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "Process_Filtered_Output",
                            "type": "object",
                            "value": {
                                "FilteredResults": [
                                    {
                                        "ProcessID": 1,
                                        "ProcessName": "A1",
                                        "ImportID": 1,
                                        "ImportName": "I1",
                                        "WorkspaceName": "A",
                                        "WorkspaceID": "8a",
                                        "ModelID": "58B4",
                                        "ModelName": "M1",
                                        "ReportType": 1
                                    }
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "SUCCEEDED"
                    ]
                }
            },
            "Parse_JSON": {
                "type": "ParseJson",
                "inputs": {
                    "content": "@variables('ReportTypeCollection')",
                    "schema": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "FundKey": {
                                    "type": "string"
                                },
                                "FundName": {
                                    "type": "string"
                                },
                                "ReportGroup": {
                                    "type": "string"
                                },
                                "StoredProcedure": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "FundKey",
                                "FundName",
                                "ReportGroup",
                                "StoredProcedure"
                            ]
                        }
                    }
                },
                "runAfter": {
                    "ReportTypeCollection": [
                        "SUCCEEDED"
                    ]
                }
            },
            "Filter_array": {
                "type": "Query",
                "inputs": {
                    "from": "@body('Parse_JSON')",
                    "where": "@equals(item()['FundKey'],string(variables('Process_Filtered_Output')?['FilteredResults']?[0]['ReportType']))"
                },
                "runAfter": {
                    "Process_Filtered_Output": [
                        "SUCCEEDED"
                    ]
                }
            },
            "Compose": {
                "type": "Compose",
                "inputs": "@body('Filter_array')",
                "runAfter": {
                    "Filter_array": [
                        "SUCCEEDED"
                    ]
                }
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "type": "Request",
                "kind": "Http"
            }
        }
    },
    "kind": "Stateful"
}

Please note, you might get no outputs in Filter Array action post executing the workflow. To see the actual output click on show raw outputs.

Its a known issue and as per github ticket, this has been fixed but looks like its still occurs.

enter image description here

enter image description here

You can add Compose action to get the actual output of Filter Array action alike me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.