【Power Apps】添付ファイルをPower Automateで処理

  • 添付ファイルをPower Automateで処理
    添付ファイルをPower Appsでデータソースとして登録せずにPower Automateで処理する方法。

    添付ファイルコントローラーはデータソースに一時的にShare Pointを追加し
    Formを作ろうとすると、添付ファイルコントローラーが自動的に追加されるので、
    その添付ファイルコントローラーを切り取りして使うと効率が良い。

    Galleryを追加しておき、Itemsには「colItemAttachmentFile」を設定しておく。
    Gallery内にはテキストと画像を配置し、それぞれ「ThisItem.Name」と「ThisItem.Value」を設定しておく。
    Galleryは非表示としておく。

    画面でボタンをクリックしたら以下の処理を行う。

    ClearCollect(colItemAttachmentFile, S01_atc_添付ファイル.Attachments);
    ForAll(S01_gly_添付ファイル一覧.AllItems As tmp,
        Collect(colUpdateFile,
            {
                Title: tmp.Name,
                FileData: tmp.S01_obj_添付ファイルオブジェクト.Image,
                Name: tmp.Name,
                Value: tmp.S01_obj_添付ファイルオブジェクト.Image
            }
        )
    );
    Collect(colItemBase, {添付ファイル: colUpdateFile});
    Set(gblJSONData, JSON(colItemBase, JSONFormat.IncludeBinaryData));
    
    PowerAutomate名称.Run(gblJSONData)
    

    Power Automateの処理は以下の通り。
    ・Share Pointコネクタ-新しいフォルダの作成
     一覧またはライブラリ:ドキュメント
     フォルダーのパス:00_管理/添付資料/Share PointのID/日付

    ・それぞれに適用する:添付ファイル
     前のステップから出力を選択します:body(‘JSON_の解析’)

    ・JSONの解析:添付ファイル
     Content:items(‘それぞれに適用する:添付ファイル’)[‘添付ファイル’]
     Schema:以下の内容

    {
        "type":"array",
        "items": {
            "type":"object",
            "properties": {
                "FileData": {
                    "type":"string"
                },
                "Title": {
                    "type":"string"
                }
            },
            "required": [
                "FileData",
                "Title"
            ]
        }
    }
    

    ・それぞれに適用する:添付ファイル単一
     前のステップから出力を選択します:body(‘JSON_の解析:添付ファイル’)

    ・変数の設定
     名前:添付ファイル識別子
     値:string(variables(‘添付ファイル識別子整数’))

    ・変数の設定
     名前:添付ファイル名分割配列
     値:split(items(‘それぞれに適用する:添付ファイル単一’)[‘Title’],’.’)

    ・変数の設定
     名前:添付ファイル名の日付付与
     値:concat(variables(‘添付ファイル名分割配列’)[sub(length(variables(‘添付ファイル名分割配列’)), 2)],’_’,variables(‘添付ファイル識別子’))

    ・変数の設定
     名前:添付ファイル名禁則文字置換
     値:replace(items(‘それぞれに適用する:添付ファイル単一’)[‘Title’],variables(‘添付ファイル名分割配列’)[sub(length(variables(‘添付ファイル名分割配列’)), 2)],variables(‘添付ファイル名の日付付与’)),’>’,”)
    上記以外に「<」などの禁則文字を空欄に置換

【Power Automate】Excelファイルの操作

  • Excelファイルを開く
    監視が成功するとJSONが戻ってくるので、その中から34桁のブックIDを取得し、
    それをExcel操作用に利用する必要がある。
    参考サイト
    ttps://qiita.com/fukasuke/items/1502b9b9b045c78f67e9

    具体的な取得方法としては戻り値の中から「Thumbnail」を取得する。
    Thumbnailを「&」で分解すると以下の形式となるので、
    「docid」をsubstringやindexOfを駆使して取得する。

    https://japaneast1-mediap.svc.ms/transform/thumbnail
    ?provider=spo
    &inputFormat=xlsx
    &cs=fFNQTw
    &docid=https%3a%2f%2f・・・
    &width=xxx
    &height=xxx
    

【Power Automate】動的コンテンツと式

  • 動的コンテンツと式
    Power Automateで選択した動的コンテンツはすべて式で表現できる。
    例)以下は同じ意味

    substring(variables('変数名'), indexOf(variables('変数名'), 'https%3a%2f%2f'))
    substring(動的コンテンツから指定, indexOf(動的コンテンツから指定, 'https%3a%2f%2f'))
    

    動的コンテンツから指定=variables(‘変数名’)は同じオブジェクトを指している。

【Power Automate】選択肢のコード値

  • Power Automateで選択肢のコード値を使う
    テーブルの選択肢を設定画面から見ると「530,100,000」のように
    カンマ区切りで表記されるが、
    PowerAutomateで条件式で利用する際は
    数値で「530100000」のようにカンマを除去して利用する。

【Power Automate】データ取得後の条件分岐

  • データ取得後の条件分岐
    以下の内容を「式」に設定する。

    length(body('コネクタの名称')?['value'])
    

    参考サイト
    ttps://powerusers.microsoft.com/t5/General-Power-Automate/Get-record-count-of-Dynamics-quot-List-Records-quot/td-p/306269
    英語のフォーラムに実例が色々ある。