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

PowerApps ThisRecordの注意点

Last updated at Posted at 2024-11-06

元データ

Parent_table

product_id product_name
1 商品A
2 商品B

Child_table

id product_id year sales delete_flg
1 1 2024 100 0
2 1 2025 200 0
3 1 2026 300 0
4 2 2024 10 0
5 2 2025 20 0
6 2 2026 30 0

Target_table

product_id product_name
2 商品B

ThisRecordの使用

Clear(Child_table_col);
ForAll(Target_table,

    ForAll(Filter(Child_table,product_id = ThisRecord.product_id),
        Collect(Child_table_col,ThisRecord);
    );

    UpdateIf(
        Child_table
        product_id = ThisRecord.product_id
        ,
        {

            delete_flg: 1
        }
    );
    
    Patch(
         Child_table,
         LookUp(Child_table,product_id= ThisRecord.product_id),
         {
            delete_flg: 1
        }
    );
);

問題点

1.上記のように実装すると、Child_table_colはChild_tableのデータがすべて格納されます。
原因は、Filter(Child_table,product_id = ThisRecord.product_id)のThisRecord.product_idがChild_table自分のproduct_idと認識されます。
image.png

2.Child_tableのdelete_flgがすべて1に更新されます。
原因は、ThisRecord.product_idはUpdateIfのChild_tableが認識されています

3.Child_tableのdelete_flgがすべて1に更新されます。
原因は、ThisRecord.product_idはUpdateIfのChild_tableが認識されています

改善方法

Clear(Child_table_col);
ForAll(Target_table,

    ForAll(Filter(Child_table As B,B.product_id = Target_table[@product_id]),
        Collect(Child_table_col,ThisRecord);
    );

    UpdateIf(
        Child_table As C
        C.product_id = Target_table[@product_id]
        ,
        {

            delete_flg: 1
        }
    );
    
    Patch(
         Child_table As D,
          LookUp(Child_table,D.product_id= Target_table[@product_id]),
         {
            delete_flg: 1
        }
    );
);

参考サイト

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