2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerAutomateで配列を作成した(つもり)が添字アクセスするとエラー

Last updated at Posted at 2025-06-23

本当に初歩的な話題で恐縮ですが、初歩的過ぎてトラブルシューティングに時間がかかったお話。

Problem

PowerAutomateのフロー内で「作成」(Compose)アクションにより以下のような文字列型の配列を作成:

['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟']

その後のロジック内で配列要素に添字アクセス(例:foo[1])を試みたところエラーが発生:

アクション '<添字アクセスを試みたアクション名>' に失敗しました: Unable to process template language expressions in action '<添字アクセスを試みたアクション名>' inputs at line '0' and column '0': 'The template language expression 'outputs('<配列を作成したアクション名>')[<添字>]' cannot be evaluated because property '1' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

文字列型はプロパティ選択(foo['bar']形式のアクセス)をサポートしていない─と。

Solution

「作成」アクションにおける配列リテラルの記述を、シングルクォートを使ったものからダブルクオートを使ったものにあらためる。

変更前:

['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟']

変更後:

["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]

PowerAutomateでは関数式が求められるコンテキストでは文字列リテラルはシングルクォートを使って表す必要がある('foo'形式の記述)。

一方「作成」コンポーネントの入力欄への直接記述など、そこに記述された内容がそのままJSONとして評価されるコンテキストでは文字列リテラルはダブルクオートを使って表す必要がある("foo"形式の記述)。JSONなので文字列はダブルクオート・・・仕様通りです。

そしてPowerAutomateにおいて後者のコンテキストで JSONとしてパースできない内容が入力されている場合、その内容全体で1つの文字列として解釈 される。
「変更前」のコードはJSONとしてパースできないため、以下のような文字列として解釈される:

"['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟']"

つまり今回の問題は「文字列を要素とする配列を作成したつもりが、実際には配列リテラルを内容とする文字列を作成していた」ということ。
うっかりミスでした。。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?