Skip to main content

Notifications

Community site session details

Community site session details

Session Id : VUmQ/iw7XnToexKul/r6Z2
Power Apps - Building Power Apps
Answered

Patching collection to SharePoint list and add a collection upload ID

Like (1) ShareShare
ReportReport
Posted on 22 Aug 2023 11:46:20 by 20

Hello fellow developers ๐Ÿ™‚

I have a Power App with a Collection called offerCol with the following columns:

LicensName
TermDuration
BillingPlan
SkuId
Price
Quantity
LineDiscountRate
Total

The collection is connected to a power apps gallery.
I perform different modifications to the collection while playing the app. When all my modifications are completed, I want to be able to bulk save all records in the collection, into a SharePoint List called OfferList. For this purpose, I have created a button outside the gallery, that takes all records in offerCol and patch it as new records into the SharePoint list. The code in the buttons OnSelect property looks like this.

ForAll(

    offerCol,

    Patch(

        OfferList,

        Defaults(โ€˜OfferList '),

        {

            LicenseName: LicenseName,

            TermDuration: TermDuration,

            BillingPlan: BillingPlan,

            SkuId: SkuId,

            Price: Price,

            Quantity: Quantity,

            LineDiscountRate: LineDiscountRate,

            Total: Total

        }

    )

)
The SharePoint list (OfferList) have the following columns:
LicensName
TermDuration
BillingPlan
SkuId
Price
Quantity
LineDiscountRate
Total
OfferId

I now want you to modify the code above so that all records in offerCol gets the exact same unique ID called OfferId.

For every record in offerCol to be patched into the SharePoint list, this ID should be applied and loaded into the โ€œOfferIdโ€ column in the list. The ID should be unique in the sense that it should only exist once for a group of records in the SharePoint list (OfferList).
The idea here is, to be able to detect a group of multiple rows in the SharePoint list, by their single collective collection upload ID (in this case called (offerId).
The idea looks like this.

Ebbe1988_0-1692704425368.png

Since Iโ€™m stuck and have had a hard time finding a solution for this, I would really appreciate if a gentle person would help me modify the code.

  • Ebbe1988 Profile Picture
    20 on 22 Aug 2023 at 12:19:22
    Re: Patching collection to SharePoint list and add a collection upload ID

    Hi Prabhakar_S

    Thank you for your very quick and helpful response. Now my problem is solved and it creates a unique upload ID (OfferId) ๐Ÿ˜„

  • Verified answer
    Prabhakar_S Profile Picture
    735 Super User 2025 Season 1 on 22 Aug 2023 at 11:57:05
    Re: Patching collection to SharePoint list and add a collection upload ID

    Hi @Ebbe1988 ,

     

    Please try this formula,

     

    ClearCollect(
    offerColWithOfferId,
    AddColumns(
    offerCol,
    "OfferId",
    Text(Today(), "[$-en-US]yyyymmdd") & Text(Now(), "hhmmss")
    )
    );

    ForAll(
    offerColWithOfferId,
    Patch(
    OfferList,
    Defaults(OfferList),
    {
    LicenseName: LicenseName,
    TermDuration: TermDuration,
    BillingPlan: BillingPlan,
    SkuId: SkuId,
    Price: Price,
    Quantity: Quantity,
    LineDiscountRate: LineDiscountRate,
    Total: Total,
    OfferId: OfferId
    }
    )
    );

     

    Thanks!!!

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 22 Aug 2023 at 11:55:44
    Re: Patching collection to SharePoint list and add a collection upload ID

    Certainly! I understand the requirement, and I'm here to help you modify the formula to achieve the desired functionality.

    First, you'll need to generate a unique OfferId that can be applied to all items in the offerCol collection. One way to do this is to use the Now() function to create a timestamp, which can be used as a unique ID. You can then use ClearCollect to create a temporary collection with the same data from offerCol but with the additional OfferId column.

    Here's the updated formula:

    1. Create the OfferId using the current timestamp.
    2. Use ClearCollect to create a temporary collection with the OfferId.
    3. Patch the temporary collection to the SharePoint list.
    // Generate unique OfferId based on the current timestamp
    Set(gloOfferId, Text(Now(), "[$-en-US]yyyymmddhhmmss"))
    
    // Create a temporary collection with the same data from offerCol and the additional OfferId
    ClearCollect(
     colTemp,
     AddColumns(
     offerCol,
     "OfferId", gloOfferId
     )
    )
    
    // Go through the temporary collection and Patch it to the SharePoint list
    ForAll(
     colTemp,
     Patch(
     OfferList,
     Defaults(OfferList),
     {
     LicenseName: LicenseName,
     TermDuration: TermDuration,
     BillingPlan: BillingPlan,
     SkuId: SkuId,
     Price: Price,
     Quantity: Quantity,
     LineDiscountRate: LineDiscountRate,
     Total: Total,
     OfferId: OfferId // Using the unique OfferId for the collection upload
     }
     )
    )
    

     

    However, I recommend Patch outside ForAll - to do so, try below:

    1. Generate the unique OfferId as before.
    2. Use ClearCollect to create a temporary collection (colTemp) with the OfferId.
    3. Create another temporary collection (colChanges) using ForAll to go through the colTemp and prepare the records you want to patch.
    4. Use Patch outside of ForAll to apply the changes to the SharePoint list.
    // Generate unique OfferId based on the current timestamp
    Set(gloOfferId, Text(Now(), "[$-en-US]yyyymmddhhmmss"))
    
    // Create a temporary collection with the same data from offerCol and the additional OfferId
    ClearCollect(
     colTemp,
     AddColumns(
     offerCol,
     "OfferId", gloOfferId
     )
    )
    
    // Go through the temporary collection and prepare the records for patching
    ClearCollect(
     colChanges,
     ForAll(
     colTemp,
     {
     LicenseName: LicenseName,
     TermDuration: TermDuration,
     BillingPlan: BillingPlan,
     SkuId: SkuId,
     Price: Price,
     Quantity: Quantity,
     LineDiscountRate: LineDiscountRate,
     Total: Total,
     OfferId: OfferId // Using the unique OfferId for the collection upload
     }
     )
    )
    
    // Patch the prepared records to the SharePoint list
    Patch(
     OfferList,
     Defaults(OfferList),
     colChanges
    )
    

     

    See if it helps @Ebbe1988 

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

๐ŸŒธ Community Spring Festival 2025 Challenge ๐ŸŒธ

WIN Power Platform Community Conference 2025 tickets!

Markus Franz โ€“ Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Communityโ€ฆ

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started