Microsoft Flow has data types such as basic types, arrays, and maps (objects), but because the operations are wrapped in a GUI, it is very difficult to understand how to get from the data to the desired element values.
Often, after much trial and error with the mouse, it is finally possible to write something that could be written simply if one knew how to refer to the value.
So, without going into the specifics of Flow, I would like to briefly summarize the data referencing method in Flow.
Test Environment Preparation
It is easy to understand if you prepare a simple test Flow and actually try things out.
You can create data with any input in [Action] - [Data Manipulation] - [Create], so let's try to see how Flow manipulates data by creating "test" data and then creating "out" data with that as input.
For example, create a Flow in which "test" is set to the number "12345" and "out" is entered as "test".
The result is that "out" is the number "12345".
How to know the reference name
When assigning "test" to "out," you do not need to enter "test" manually, as it appears in the "dynamic content" list, It will appear in the list of "dynamic contents" and will be set by a mouse click from there.
Before Set
after the set
However, this friendly design conversely makes it difficult to know how to manually enter "test" when you want to use it in an expression.
You can easily find out how to refer to "test" manually by following the steps below.
procedure
1. Select [test]-[output] from "Dynamic Content" and set "test" as the input for "out
2, Select "Output" (Shift+Left arrow)
.
3, Ctrl+C to copy
4. Paste on a notepad, etc.
The following text will then be pasted.
@{outputs('test')}
The "outputs('test')" without "@{}" is the identity of the input "output" of "out".
Writing "outputs('test')" in the expression is equivalent to selecting [test]-[output] from "dynamic content".
Basic This writing style allows you to refer to "dynamic content" in "expressions".
data element reference method
How to refer to elements of an array or map in Flow.
Accessing array elements
It can be accessed with obj[<idx>]
.
outputs('test')[1] // 2番目の要素を取得
Execution Result
Accessing map elements
You can access it with obj.<colName>
.
outputs('test').col1 // col1の要素を取得
Execution Result
Element names can also be referenced by specifying them as strings in the following way so that they can be referenced even if they contain Japanese characters or spaces.
It can be accessed with obj?['<colName>']
.
outputs('test')?['col1'] // col1の要素を取得
Execution Result
practice
For example, even within the "Apply to each" loop, the reference name for "dynamic content" can be obtained in the same way.
The "current item" in the loop is items('Apply_to_each')
, so to get the "id" from it, we use items('Apply_to_each').id
.
Execution Result
Even if the data is acquired from various other connectors,
- Check the reference name for "dynamic content.
- Use the array/map access method
The desired element can be accessed by
For example, "get the value of column 'id' of the first record of a database query result" can be done with body('query').ResultSets.Table1[0].id
in one shot.
Execution Result
About @.
The statements "@" and "@{...}" are often used to expand variables and expressions in strings.
For example, if you want to pass items in a loop as JSON data in some action, you can describe it as follows.
{ "body": "@{items('Apply_to_each')}はアイテムデータです" }
Both "@" and "@{...}" have the same function, and "@{...}" is used to specify the range of expansion.
Also, if you want to use "@" as a letter rather than an expansion, write "@@" twice.
impressions
The data reference had been done only by actions, but now the description has been simplified and the outlook has been improved at a stroke.