cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
imranamikhan
Advocate I
Advocate I

Bulk update AND Bulk Create

Hi everyone,

 

Does anyone know if it possible to Bulk create and Bulk update a SharePoint list with one button/one execution?

 

I have the following code working in the Gallery for single records. This will either create an item or update an item if the item already exists:

 

 

If(CountRows(Filter(DB_MarketFeedback, CustomerID = ThisItem.Customer)) > 0,

Patch(

    DB_MarketFeedback,

    LookUp(DB_MarketFeedback,CustomerID=ThisItem.Customer),

    {

        Title: Dropdown_Status.SelectedText.Value,

        Comment: TextInput_Comment.Text

        }),

Patch(

    DB_MarketFeedback,

    Defaults(DB_MarketFeedback),

    {

        Title: Dropdown_Status.SelectedText.Value,

        Comment: TextInput_Comment.Text,

        CustomerID: ThisItem.Customer

        }))

 

 

I have following working to update all items in the Gallery:

 

 

ForAll(
    Gallery1.AllItems,
    Patch(
        DB_MarketFeedback,
        LookUp(
            DB_MarketFeedback,
            CustomerID = Customer
        ),
        {
            Validation_Status: Dropdown_Status.SelectedText.Value,
            Comment: TextInput_Comment.Text
        }
    )
)

 

 

And I have the following working to create items in the Gallery:

 

 

ForAll(
    Gallery1.AllItems,
        Patch(
        DB_MarketFeedback,
        Defaults(DB_MarketFeedback),
        {
            Title: Dropdown_Status.SelectedText.Value,
            Comment: TextInput_Comment.Text,
            CustomerID: Customer
        }
    )
)

 

 

Any thoughts would be appreciated.

Best regards,

Ami

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @imranamikhan ,

 

Could you tell me:

  • Whats the Items property of your gallery control?

 

I assume:

  1. The Items property of the gallery control is a single column table.
  2. Customer column is the only column in the table.
  3. When the record exists, modify the value of the “Validation_Status” column and the value of the “Comment” column.
  4. When the record does not exist, create a new record. Fill in the value of Tilte column, the value of Comment column and the value of CustomerID column.

 

If my assumptions are correct, the point is to use the If() function to determine whether there is an existing record.

If so, modify the existing record. If not, create a new record.

 

I've made a test for your reference:

1\ This is my list DB_MarketFeedback. There are some test records in it .

v-xiaochen-msft_0-1607928097119.jpeg

 

v-xiaochen-msft_1-1607928097121.png

 

 

2\ Add a gallery control and set its Items property to:

Table({Customer:1},{Customer:2},{Customer:3},{Customer:4},{Customer:5})

v-xiaochen-msft_2-1607928097121.png

 

 

3\ Add a dropdown control Dropdown_Status and set its Items property to:

Table({Test:"Test1"},{Test:"Test2"})

 

4\ Add a Textinput control TextInput_Comment .

 

5\ Add a button control and set its onselect property to:

ForAll(

    Gallery1.AllItems,

    If(

        CountRows(

            Filter(

                DB_MarketFeedback,

                CustomerID = Customer

            )

        ) > 0,

        Patch(

            DB_MarketFeedback,

            LookUp(

                DB_MarketFeedback,

                CustomerID = Customer

            ),

            {

                ' Validation_Status': Dropdown_Status.SelectedText.Value,

                Comment: TextInput_Comment.Text

            }

        ),

        Patch(

            DB_MarketFeedback,

            Defaults(DB_MarketFeedback),

            {

                Title: Dropdown_Status.SelectedText.Value,

                Comment: TextInput_Comment.Text,

                CustomerID: Customer

            }

        )

    )

)

 

6\ The result is as follows:

v-xiaochen-msft_3-1607928097122.jpeg

 

v-xiaochen-msft_4-1607928097124.png

 

 

Best Regards,

Wearsky

View solution in original post

3 REPLIES 3
flugaoveltem
Resolver III
Resolver III

Hello @imranamikhan 

 

The Gallery control does not support multi-selection, I think you can add a Checkbox control on your gallery, update OnSelect property with: 
Collect(Selected,ThisItem)

 

That will create a collection with all selected items of the gallery, use UpdateIf to change the values then submit the changes with Forall and Patch
Take a look in this article
https://sachinbansal.blog/2018/08/06/powerapp-cds-multi-select-items-in-gallery-using-checkbox-bulk-...

 

 

v-xiaochen-msft
Community Support
Community Support

Hi @imranamikhan ,

 

Could you tell me:

  • Whats the Items property of your gallery control?

 

I assume:

  1. The Items property of the gallery control is a single column table.
  2. Customer column is the only column in the table.
  3. When the record exists, modify the value of the “Validation_Status” column and the value of the “Comment” column.
  4. When the record does not exist, create a new record. Fill in the value of Tilte column, the value of Comment column and the value of CustomerID column.

 

If my assumptions are correct, the point is to use the If() function to determine whether there is an existing record.

If so, modify the existing record. If not, create a new record.

 

I've made a test for your reference:

1\ This is my list DB_MarketFeedback. There are some test records in it .

v-xiaochen-msft_0-1607928097119.jpeg

 

v-xiaochen-msft_1-1607928097121.png

 

 

2\ Add a gallery control and set its Items property to:

Table({Customer:1},{Customer:2},{Customer:3},{Customer:4},{Customer:5})

v-xiaochen-msft_2-1607928097121.png

 

 

3\ Add a dropdown control Dropdown_Status and set its Items property to:

Table({Test:"Test1"},{Test:"Test2"})

 

4\ Add a Textinput control TextInput_Comment .

 

5\ Add a button control and set its onselect property to:

ForAll(

    Gallery1.AllItems,

    If(

        CountRows(

            Filter(

                DB_MarketFeedback,

                CustomerID = Customer

            )

        ) > 0,

        Patch(

            DB_MarketFeedback,

            LookUp(

                DB_MarketFeedback,

                CustomerID = Customer

            ),

            {

                ' Validation_Status': Dropdown_Status.SelectedText.Value,

                Comment: TextInput_Comment.Text

            }

        ),

        Patch(

            DB_MarketFeedback,

            Defaults(DB_MarketFeedback),

            {

                Title: Dropdown_Status.SelectedText.Value,

                Comment: TextInput_Comment.Text,

                CustomerID: Customer

            }

        )

    )

)

 

6\ The result is as follows:

v-xiaochen-msft_3-1607928097122.jpeg

 

v-xiaochen-msft_4-1607928097124.png

 

 

Best Regards,

Wearsky

View solution in original post

imranamikhan
Advocate I
Advocate I

Thank you very much @v-xiaochen-msft. I was not clear on combining create and update in one execution and this is perfect. 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,546)