Googleアナリティクス

2019年8月29日木曜日

Diff between collections with LogicApps / Flow

In Logic Apps and Flow, there are so many opportunities to work with arrays and collections, and there are many things to do. A simple method using filtering was created by obtaining the difference between collections (data that exists only in B between A and B) for which no better way was found.

If the target is an array, you can easily specify it using the filter action. However, in the case of a collection, it cannot be filtered as it is. If you create a process obediently, I think that there are many ways to check if it exists for each case in a loop using ForEach and add it to a variable if it does not exist. Although the requirements can be met in this way, the number of actions and execution time will increase dramatically as the number of target data increases. Especially in the case of Logic Apps, the number of actions increases = it is directly linked to the increase in billing, so we want to keep the number of actions as much as possible.

The overall process flow is as follows.

As sample data, an array with JSON values is created as follows.

Collection of A is set to name with values ​​A, B, C, D, E, and the collection of B is set to A, B, C, E, F so that a difference occurs. Compare A and B and try to get only those with name = D that only exist in A.

For this purpose, it is best to use filtering, so only the items to be compared are extracted to create an array. You have created a CSV with no header information, create data that can be converted to an array.

You can extract only the comparison items, so convert it to an array.

It is converted to an array using the split function, but at that time it comes with a line feed code, which is a problem in Logic Apps and Flow. It is described that the array is created by dividing each line break from the result of conversion using the uriComponent function.

split(uricomponent(body('AコレクションからCSVテーブルの作成')),'%0D%0A')

Now that the array has been created, you can filter it. Specify collection B as the target, and set the filter condition as follows.

contains(outputs('Aコレクションから比較要素のみで配列化'), item().name)

If the result of the above function expression is False, it can be determined that only the B collection does not exist in the A collection. Difference between collections can be acquired with just 3 actions regardless of the number of records. If the contains function is targeted an array, it can be easily determined whether it contains or not, so use the creation of an array focused only on the values ​​to be compared.

0 件のコメント:

コメントを投稿