Power AutomateのスイッチにSharePointリストの選択肢列を使用したいとき、少し手間取ったのでメモ。
やりたいこと
こんな感じで選択肢列があるSharePointリストをPower Automateのスイッチで使いたいときのお話し。

列名をそのまま選ぶとエラーになる
こんな感じでスイッチの「オン」に選択肢列の名前を選ぶと、



フローはエラーを発生させる。


これはPower Automateのスイッチが使えるデータは「整数」か「文字列」だけなんだけど、SharePointリストの選択肢列のデータ型が「オブジェクト」だから発生するエラー。
選択肢列名にvalueがついている項目を選ぶとスイッチで使用できる
そこでこんな感じで列名にValueがついている項目を選ぶと、


フローは無事動く。


値が入っていない可能性のあるときのスイッチ
もし選択肢列が任意項目で値が入っていない可能性がある場合、


さっきのフローをそのまま実行すると、またエラーが発生する。


これはPower Automateのスイッチがnullを扱えないため発生するエラー。
なのでスイッチに入れる前にnullチェックをする必要があるんだけど、if文を使ってしまうとネストが深くなってしまっていまいち読みにくくなってしまう。。。
Coalesce関数を使う
そこでこちらのブログで紹介されているCoalesce関数を使用する方法でフローを書けば、かなりきれいにフローを書くことができる。
![]()

Improve your switch case with coalesce in Power Automate
Within the switch don't use the Choice Value, but use the Choice value inside a coalesce function:
まずさっきの「選択肢列+Value」の項目をコピーして


式タブで貼りつけ。


先頭の「@{」と末尾の「}」を消したらCoalesceで囲んであげて、


Coalesce関数の第2引数に選択肢に含まれない適当な文字列(今回は「unknown」)を渡してあげる。


これでフローを実行すると選択肢列に選択がない(値がNullの)場合、文字列「unknown」がスイッチに渡されるため既定のアクションが実行される。


わりと単純な工夫だけど使いやすい方法だったのでメモ。
コメント