web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Edit & save feature fo...
Power Apps
Suggested Answer

Edit & save feature for a Gallery in Power Apps

(0) ShareShare
ReportReport
Posted on by 14
I have an app created by using power apps in my organization.
 
On a screen I have a gallery and I want to give edit and save access for each cell in the gallery.
The gallery also contains a row to attach pdfs using the edit form option in power apps.
I have created an Edit/Save toggle icon and tried some code too, but the data is not saving properly, sometimes it is saving sometimes it is not and taking too much time. I think that the edit form I'm using the column for attaching pdfs might be the reason for this data rewriting issue I'm facing here.
 
there is some math logic for column to while saving and updating in the code, the save option should not update the only the data source which is a SharePoint list of that gallery only, but it should update some other SharePoint lists also based on some conditions.
 
I am attaching the code I have used too.
I need a reliable way to make this feature work properly.
 
If(
    !varEditMode,
 
    /* ================= ENTER EDIT MODE ================= */
    Set(varEditMode, true),
 
    /* ================= SAVE MODE ================= */
 
    /* Freeze gallery rows to avoid mutation */
    ClearCollect(
        colGallerySnapshot,
        Gallery10.AllItems
    );
 
    ForAll(
        colGallerySnapshot As Row,
 
        With(
            {
                /* ===== PROJECT NUMBER & PREFIX ===== */
                projectNo: Row.'PROJECT NUMBER',
                prefix:
                    If(
                        IsBlank(Row.'PROJECT NUMBER'),
                        Blank(),
                        Left(Row.'PROJECT NUMBER', 3)
                    ),
 
                /* ===== READ EDITED VALUES (OR KEEP OLD) ===== */
                newAllocatedQty:
                    If(
                        IsBlank(
                            LookUp(Gallery10.AllItems, ID = Row.ID).TextInput18.Text
                        ),
                        Row.'ALLOCATED QUANTITY',
                        Value(
                            LookUp(Gallery10.AllItems, ID = Row.ID).TextInput18.Text
                        )
                    ),
 
                newReleasePlan:
                    If(
                        IsBlank(
                            LookUp(Gallery10.AllItems, ID = Row.ID).DatePicker3.SelectedDate
                        ),
                        Row.'RELEASE PLAN',
                        LookUp(Gallery10.AllItems, ID = Row.ID).DatePicker3.SelectedDate
                    ),
 
                newReleaseDate:
                    If(
                        IsBlank(
                            LookUp(Gallery10.AllItems, ID = Row.ID).DatePicker5.SelectedDate
                        ),
                        Row.'RELEASE DATE',
                        LookUp(Gallery10.AllItems, ID = Row.ID).DatePicker5.SelectedDate
                    ),
 
                newRemarks:
                    If(
                        IsBlank(
                            LookUp(Gallery10.AllItems, ID = Row.ID).TextInput14.Text
                        ),
                        Row.REMARKS,
                        LookUp(Gallery10.AllItems, ID = Row.ID).TextInput14.Text
                    )
            },
 
            /* ================= PROJECT ALLOCATION ================= */
            Patch(
                'PROJECT ALLOCATION',
                LookUp('PROJECT ALLOCATION', ID = Row.ID),
                {
                    'PROJECT NUMBER': projectNo,
                    'SUBASSEMBLY NUMBER': Row.'SUBASSEMBLY NUMBER',
                    'FO NUMBER': Row.'FO NUMBER',
                    BCGROUP: Row.BCGROUP,
                    Title: Row.Title,
 
                    'ALLOCATED QUANTITY': newAllocatedQty,
                    'RELEASE PLAN': newReleasePlan,
                    'RELEASE DATE': newReleaseDate,
                    REMARKS: newRemarks,
 
                    PRESENTQUANTITY:
                        If(
                            newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                            (Row.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY')
                                - newAllocatedQty,
                            Row.PRESENTQUANTITY
                        )
                }
            );
 
            /* ================= PREFIX ROUTING ================= */
            Switch(
                prefix,
 
                /* ---------- 77 ---------- */
                "77",
                With(
                    {
                        rec77:
                            LookUp(
                                'New releases',
                                SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                                PROJECTNUMBER     = projectNo &&
                                FONUMBER          = Row.'FO NUMBER' &&
                                BCGROUP           = Row.BCGROUP
                            )
                    },
                    If(
                        !IsBlank(rec77),
                        Patch(
                            'New releases',
                            rec77,
                            {
                                ALLOCATEDQUANTITY: newAllocatedQty,
                                PRESENTQUANTITY:
                                    If(
                                        newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                                        (rec77.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY')
                                            - newAllocatedQty,
                                        rec77.PRESENTQUANTITY
                                    )
                            }
                        )
                    )
                ),
 
                /* ---------- 75 ---------- */
                "75",
                With(
                    {
                        rec75:
                            LookUp(
                                'New releases(75...)',
                                SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                                PROJECTNUMBER     = projectNo &&
                                FONUMBER          = Row.'FO NUMBER' &&
                                BCGROUP           = Row.BCGROUP
                            )
                    },
                    If(
                        !IsBlank(rec75),
                        Patch(
                            'New releases(75...)',
                            rec75,
                            {
                                ALLOCATEDQUANTITY: newAllocatedQty,
                                PRESENTQUANTITY:
                                    If(
                                        newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                                        (rec75.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY')
                                            - newAllocatedQty,
                                        rec75.PRESENTQUANTITY
                                    )
                            }
                        )
                    )
                ),
 
                /* ---------- 78 ---------- */
                "78",
                Patch(
                    'PROJECT ALLOCATION(78...)',
                    LookUp(
                        'PROJECT ALLOCATION(78...)',
                        SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                        PROJECTNUMBER     = projectNo
                    ),
                    {
                        ALLOCATEDQUANTITY: newAllocatedQty
                    }
                )
 
                /* ---------- 716 / OTHERS ---------- */
                /* No extra patch */
            )
        )
    );
 
    Set(varEditMode, false);
 
    Notify(
        "Changes have been saved successfully.",
        NotificationType.Success
    )
)
Categories:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at
    There are a number of things here I will offer comment on that may assist
    1. ForAll is not designed to be a loop, although it can act that way if it contains an action inside it. ForAll creates a Table, which can be Patched in one action to the data source and will run much faster than individual Patches for each record. If it contains the ID of each record (as in the examples below), it will update the specific records, if not it will create new records.
       
    2. Why are you bothering with the collection ? You can patch straight off the Gallery and it makes the exercise far less complex.
       
    3. You are doing four patches to four different data sources. There is significance performance potential improvement by doing separate patches, so I have used these.
       
    4. You have used Left(TextInput18.Text, 3),but you tested output is two characters, so I have used 2.
     
    This is free-typed, so please watch commas, brackets etc.
    UpdateContext({varEditMode: true});
    Patch(
       'PROJECT ALLOCATION',
       ForAll(
          Gallery10.AllItems As Row,
          With(
             {
                newAllocatedQty: Value(Row.TextInput18.Text),
                newReleasePlan:
                Coalesce(
                   Row.DatePicker3.SelectedDate,
                   Row.'RELEASE PLAN
                ),
                newReleaseDate:
                Coalesce(
                   Row.DatePicker5.SelectedDate,
                   Row.'RELEASE DATE'
                ),
                newRemarks:
                Coalesce(
                   Row.TextInput14.Text,
                   Row.REMARKS
                )
             },
             {
                ID: Row.ID,
                'PROJECT NUMBER': Row.'PROJECT NUMBER',
                'SUBASSEMBLY NUMBER': Row.'SUBASSEMBLY NUMBER',
                'FO NUMBER': Row.'FO NUMBER',
                BCGROUP: Row.BCGROUP,
                Title: Row.Title,
                'ALLOCATED QUANTITY': newAllocatedQty,
                'RELEASE PLAN': newReleasePlan,
                'RELEASE DATE': newReleaseDate,
                REMARKS: newRemarks,
                PRESENTQUANTITY:
                If(
                   newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                   (Row.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY') - newAllocatedQty,
                   Row.PRESENTQUANTITY
                )
             }
          )
       )
    );
    Patch(
       'New releases',
       ForAll(
          Filter(
             Gallery10.AllItems,
             Left('PROJECT NUMBER', 2) = "77"
          ) As Row,
          With(
             {
                newAllocatedQty: Value(Row.TextInput18.Text),
                rec77: 
                LookUp(
                   'New releases',
                   SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                   PROJECTNUMBER = Row.'PROJECT NUMBER' &&
                   FONUMBER = Row.'FO NUMBER' &&
                   BCGROUP = Row.BCGROUP
                )
             },
             If(
                !IsBlank(rec77),
                {
                   ID: rec77.ID,
                   ALLOCATEDQUANTITY: newAllocatedQty,
                   PRESENTQUANTITY:
                   If(
                      newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                      (rec77.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY') - newAllocatedQty,
                      rec77.PRESENTQUANTITY
                   )
                }
             )
          )
       )
    );
    Patch(
       'New releases(75...)',
       ForAll(
          Filter(
             Gallery10.AllItems,
             Left('PROJECT NUMBER', 2) = "75"
          ) As Row,
          With(
             {
                newAllocatedQty: Value(Row.TextInput18.Text),
                rec75: 
                LookUp(
                   'New releases(75...)',
                   SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                   PROJECTNUMBER = Row.'PROJECT NUMBER' &&
                   FONUMBER = Row.'FO NUMBER' &&
                   BCGROUP = Row.BCGROUP
                )
             },
             If(
                !IsBlank(rec75),
                {
                   ID: rec75.ID,
                   ALLOCATEDQUANTITY: newAllocatedQty,
                   PRESENTQUANTITY:
                   If(
                      newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                      (rec75.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY') - newAllocatedQty,
                      rec75.PRESENTQUANTITY
                   )
                }
             )
          )
       )
    );
    Patch(
       'PROJECT ALLOCATION(78...)',
       ForAll(
          Filter(
             Gallery10.AllItems,
             Left('PROJECT NUMBER', 2) = "78"
          ) As Row,
          With(
             {
                newAllocatedQty: Value(Row.TextInput18.Text),
                rec78: 
                LookUp(
                   'PROJECT ALLOCATION(78...)',
                   SUBASSEMBLYNUMBER = Row.'SUBASSEMBLY NUMBER' &&
                   PROJECTNUMBER = Row.'PROJECT NUMBER' &&
                   FONUMBER = Row.'FO NUMBER' &&
                   BCGROUP = Row.BCGROUP
                )
             },
             {
                ID: rec78.ID,
                ALLOCATEDQUANTITY: newAllocatedQty,
                PRESENTQUANTITY:
                If(
                   newAllocatedQty <> Row.'ALLOCATED QUANTITY',
                   (rec78.PRESENTQUANTITY + Row.'ALLOCATED QUANTITY') - newAllocatedQty,
                   rec78.PRESENTQUANTITY
                )
             }
          )
       )
    );
    UpdateContext({varEditMode: false});
    Notify(
       "Changes have been saved successfully.",
       NotificationType.Success
    )
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
     
  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥
    Visit my blog
    Practical Power Apps    LinkedIn   

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 531 Most Valuable Professional

#2
Haque Profile Picture

Haque 261

#3
Kalathiya Profile Picture

Kalathiya 221 Super User 2026 Season 1

Last 30 days Overall leaderboard