Raj
Raj

Reputation: 95

Logicapp expression with variable within expression giving null result

I am creating logicapp expression in which I need to substitute variable within the expression.

What what I want to achieve is : something like this

@{body('actionName')?['parentName1']?['2022-10-14:14']?['142.0'][0]?['ask']}

in the above expression, variable1 & variable2 holds 2022-10-14:14 & 142.0 respectively.

to achieve this, I am trying this below which is giving me null values

Trail-1:

@{body('actionName')?['parent1']?['@variables('dateVariable')']?['@variables('priceVariable')'][0]?['ask']}

Trail-2:

@{body('actionName')?['parent1']?['@variables("dateVariable")']?['@variables("priceVariable")'][0]?['ask']}

Trail-3:

@{body('actionName')?['parent1']?["@variables('dateVariable')"]?["@variables('priceVariable')"][0]?['ask']}

None of these trails worked, please let me know if you have any clue, many thanks in advance.

Upvotes: 0

Views: 574

Answers (1)

Skin
Skin

Reputation: 11197

You need to remove your quotes.

Load this example into you tenant and it will show you a working example.

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Initialize_AUD_Property_Name": {
                "inputs": {
                    "variables": [
                        {
                            "name": "AUD Property Name",
                            "type": "string",
                            "value": "AUD"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_Currencies_Property_Name": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_Currencies_Property_Name": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Currencies Property Name",
                            "type": "string",
                            "value": "Currencies"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_JSON_Object": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_JSON_Object": {
                "inputs": {
                    "variables": [
                        {
                            "name": "JSON Object",
                            "type": "object",
                            "value": {
                                "altSpellings": [
                                    "AU"
                                ],
                                "area": 7692024,
                                "capital": [
                                    "Canberra"
                                ],
                                "capitalInfo": {
                                    "latlng": [
                                        -35.27,
                                        149.13
                                    ]
                                },
                                "car": {
                                    "side": "left",
                                    "signs": [
                                        "AUS"
                                    ]
                                },
                                "cca2": "AU",
                                "cca3": "AUS",
                                "ccn3": "036",
                                "cioc": "AUS",
                                "coatOfArms": {
                                    "png": "https://mainfacts.com/media/images/coats_of_arms/au.png",
                                    "svg": "https://mainfacts.com/media/images/coats_of_arms/au.svg"
                                },
                                "continents": [
                                    "Oceania"
                                ],
                                "currencies": {
                                    "AUD": {
                                        "name": "Australian dollar",
                                        "symbol": "$"
                                    }
                                },
                                "demonyms": {
                                    "eng": {
                                        "f": "Australian",
                                        "m": "Australian"
                                    },
                                    "fra": {
                                        "f": "Australienne",
                                        "m": "Australien"
                                    }
                                },
                                "fifa": "AUS",
                                "flag": "🇦🇺",
                                "flags": {
                                    "png": "https://flagcdn.com/w320/au.png",
                                    "svg": "https://flagcdn.com/au.svg"
                                },
                                "gini": {
                                    "2014": 34.4
                                },
                                "idd": {
                                    "root": "+6",
                                    "suffixes": [
                                        "1"
                                    ]
                                },
                                "independent": true,
                                "landlocked": false,
                                "languages": {
                                    "eng": "English"
                                },
                                "latlng": [
                                    -27,
                                    133
                                ],
                                "maps": {
                                    "googleMaps": "https://goo.gl/maps/DcjaDa7UbhnZTndH6",
                                    "openStreetMaps": "https://www.openstreetmap.org/relation/80500"
                                },
                                "name": {
                                    "common": "Australia",
                                    "nativeName": {
                                        "eng": {
                                            "common": "Australia",
                                            "official": "Commonwealth of Australia"
                                        }
                                    },
                                    "official": "Commonwealth of Australia"
                                },
                                "population": 25687041,
                                "postalCode": {
                                    "format": "####",
                                    "regex": "^(\\d{4})$"
                                },
                                "region": "Oceania",
                                "startOfWeek": "monday",
                                "status": "officially-assigned",
                                "subregion": "Australia and New Zealand",
                                "timezones": [
                                    "UTC+05:00",
                                    "UTC+06:30",
                                    "UTC+07:00",
                                    "UTC+08:00",
                                    "UTC+09:30",
                                    "UTC+10:00",
                                    "UTC+10:30",
                                    "UTC+11:30"
                                ],
                                "tld": [
                                    ".au"
                                ],
                                "translations": {
                                    "ara": {
                                        "common": "أستراليا",
                                        "official": "كومونولث أستراليا"
                                    },
                                    "bre": {
                                        "common": "Aostralia",
                                        "official": "Kenglad Aostralia"
                                    },
                                    "ces": {
                                        "common": "Austrálie",
                                        "official": "Australské společenství"
                                    },
                                    "cym": {
                                        "common": "Awstralia",
                                        "official": "Cymanwlad Awstralia"
                                    },
                                    "deu": {
                                        "common": "Australien",
                                        "official": "Commonwealth Australien"
                                    },
                                    "est": {
                                        "common": "Austraalia",
                                        "official": "Austraalia Ühendus"
                                    },
                                    "fin": {
                                        "common": "Australia",
                                        "official": "Australian liittovaltio"
                                    },
                                    "fra": {
                                        "common": "Australie",
                                        "official": "Australie"
                                    },
                                    "hrv": {
                                        "common": "Australija",
                                        "official": "Commonwealth of Australia"
                                    },
                                    "hun": {
                                        "common": "Ausztrália",
                                        "official": "Ausztrál Államszövetség"
                                    },
                                    "ita": {
                                        "common": "Australia",
                                        "official": "Commonwealth dell'Australia"
                                    },
                                    "jpn": {
                                        "common": "オーストラリア",
                                        "official": "オーストラリア連邦"
                                    },
                                    "kor": {
                                        "common": "호주",
                                        "official": "오스트레일리아 연방"
                                    },
                                    "nld": {
                                        "common": "Australië",
                                        "official": "Gemenebest van Australië"
                                    },
                                    "per": {
                                        "common": "استرالیا",
                                        "official": "قلمرو همسود استرالیا"
                                    },
                                    "pol": {
                                        "common": "Australia",
                                        "official": "Związek Australijski"
                                    },
                                    "por": {
                                        "common": "Austrália",
                                        "official": "Comunidade da Austrália"
                                    },
                                    "rus": {
                                        "common": "Австралия",
                                        "official": "Содружество Австралии"
                                    },
                                    "slk": {
                                        "common": "Austrália",
                                        "official": "Austrálsky zväz"
                                    },
                                    "spa": {
                                        "common": "Australia",
                                        "official": "Mancomunidad de Australia"
                                    },
                                    "swe": {
                                        "common": "Australien",
                                        "official": "Australiska statsförbundet"
                                    },
                                    "tur": {
                                        "common": "Avustralya",
                                        "official": "Avustralya Federal Devleti"
                                    },
                                    "urd": {
                                        "common": "آسٹریلیا",
                                        "official": "دولتِ مشترکہ آسٹریلیا"
                                    },
                                    "zho": {
                                        "common": "澳大利亚",
                                        "official": "澳大利亚联邦"
                                    }
                                },
                                "unMember": true
                            }
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_Name_Value": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Name Value",
                            "type": "string",
                            "value": "@{variables('JSON Object')?[variables('Currencies Property Name')]?[variables('AUD Property Name')]?['Name']}"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_AUD_Property_Name": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "ParameterTest1": {
                "defaultValue": "\"\"",
                "type": "String"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "method": "GET",
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Buried within there is an example expression that uses the names of the properties from a variable to extract the value.

Said expression looks like this (as you can see, no quotes) ...

variables('JSON Object')?[variables('Currencies Property Name')]?[variables('AUD Property Name')]?['Name']

Upvotes: 1

Related Questions