0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerAutomateの「選択」で string() が無視される

Last updated at Posted at 2022-08-23

今回もPowerAutomateを使ってフローを構築・運用している過程で遭遇した問題のトラブルシューティングです。

Problem

オブジェクトの配列に対して「選択」(Select)アクションを使用し、要素オブジェクトのプロパティの選択/変換を行うとき、string()関数が無視される。

例えば次のような配列があるとしましょう。この配列の要素オブジェクトにはfooというプロパティがあり、文字列型だったり数値型だったりします:

[
  {
    "foo": "123"
  },
  {
    "foo": "456"
  },
  {
    "foo": 789
  },
  {
    "foo": "012"
  }
]

ここで、プロパティfooをすべて文字列型に変換するとします:

image.png

「Map」欄のfooStringに対応する値には 式string(item()['foo'])を指定します。

これを実行すると、結果は思いもかけないものになります:

image.png

[
  {
    "fooString": "123"
  },
  {
    "fooString": "456"
  },
  {
    "fooString": 789
  },
  {
    "fooString": "012"
  }
]

つまり数値型から文字列型への変換が行われていません。。

おまけに「選択」アクションの「Switch Map to text mode」ボタンを押したり、フローの詳細画面に戻ったあと再度編集画面に遷移したりすると、式string(item()['foo'])は勝手に式item()['foo']に変換されています。

image.png

原因は不明です。
PowerAutomateが自動的に行う式の最適化のバグだろうと推測していますが実際のところはわかりません。
ちなみにこの問題はオブジェクトの配列でのみ発生し、文字列型の配列では発生しません。

Solution

対策として string()の代わりにconcat('', ...)を使用します。
つまり string(item()['foo'])の代わりに concat('', item()['foo'])と記述します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?