4

I am new to Logic Apps so bear with me. I am just trying to perform a simple lookup in an Azure Table Storage and get a value that I can store in a variable in a Logic App. Here is what my Table Storage looks like:

enter image description here

My RowKey is unique and will be my lookup value. So based on a RowKey value, I want to get the UTCOffset value and store it in a variable.

This is what I have tried so far:

enter image description here

I want to get the value returned "13.00" and just store it in a variable for further processing. Pretty simple I know, but I just can't get my head around it.

enter image description here

Oliver Nilsen
  • 1,017
  • 2
  • 12
  • 32

2 Answers2

3

You just need to use the expression as below in your "Initialize variable" action: enter image description here The whole expression is:

body('Get_entities')?['value'][0]?['UTCOFFSET']

Please pay attention to the case UTCOFFSET, in your logic you may need to use UTCoffset.

And it seems you changed the name of "Get entities" action from "Get entities" to "Get entities-UTC", so you also need to modify its name in the expression, shown as below:

body('Get_entities-UTC')?['value'][0]?['UTCoffset']

Hope it helps~

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Thanks so much Hury for the detailed answer on my simple question. It worked right away. I was missing the Expression that you were kind to provide: body('Get_entities')?['value'][0]?['UTCOFFSET'] May I just ask what the semantic of '?' is in this expression? Is this like an "XPath" for JSON that denotes if a value exist and is not null, then fetch the value property? – Oliver Nilsen May 19 '20 at 10:55
  • @OliverNilsen Sorry, I'm not clear about the `?` either. It seems if we want to get the array item, we just need use `[index]` and if we want to get the map value, we need to use `?['key']`. – Hury Shen May 19 '20 at 14:14
1

Slightly late, but if you're only trying to find a single entity, you could use the "Get Entity" step, which will only return a single entity, reducing the need for array manipulation.

Note that in Table Storage, your unique id is the combination of the Partition and Row keys - in your example above: New Zealand and 01. You'll get better performance if you're able to pass the partition key in as well.

You can then use the "Parse JSON" step to define the schema of your records, and have the different fields available in subsequent steps without having to resort to a function:

Get Entity followed by Parse JSON

You can either use the "Use sample payload" link to generate the schema automatically, or use something like:

{
    "properties": {
        "PartitionKey": {
            "type": "string"
        },
        "RowKey": {
            "type": "string"
        },
        "Timestamp": {
            "type": "string"
        },
        "UTCOffset": {
            "type": "string" // or number
        },
        "odata.etag": {
            "type": "string"
        },
        "odata.metadata": {
            "type": "string"
        }
    },
    "type": "object"
}

Alternatively you can use the Parse JSON step to handle the array returned by the Get Entities step and have a strongly typed set of objects that Logic Apps will let you loop through.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • 1
    Gladly I found this answer. I had a similar challenge but did not know how to get the value of a table entity. I completely miss the `Parse JSON` data operations action. – Junius Feb 09 '23 at 22:14