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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Insert working in If s...
Power Apps
Unanswered

Insert working in If statement but update not working

(0) ShareShare
ReportReport
Posted on by 25
I have a Power App connected to a SQL database.
 
I have the following code for either inserting new records or updating an IsApproved field on existing records - currently the insert works but the update doesn't.
 
ForAll(
    colShiftReg,
    If( 
        IsBlank(ThisRecord.ShiftRegisterId), 
        Patch(
            ShiftRegister,
            Defaults(ShiftRegister),
            { 
                SupervisorId: ThisRecord.SupervisorId, 
                DepotId: ThisRecord.DepotId, 
                ShiftDate: SR_dtp_Shift_Date.SelectedDate + Time(Hour(Now()), Minute(Now()), 0),
                ShiftDetailsId: ThisRecord.ShiftDetailsId, 
                OperativeId: ThisRecord.OperativeId, 
                Hours: ThisRecord.Hours, 
                ShiftType: ThisRecord.ShiftType, 
                Enhancement: ThisRecord.Enhancement, 
                Comments: ThisRecord.Comments, 
                ContractId: ThisRecord.ContractId, 
                IsApproved: true, 
                IsDeleted: ThisRecord.IsDeleted, 
                RegisterId: GUID(varRegisterId)
            } 
        ),
        Patch(
            ShiftRegister,
            LookUp(ShiftRegister, ShiftRegisterId = ThisRecord.ShiftRegisterId), 
            { 
                IsApproved: true
            }
        );
        Notify("Patch completed for Id" & ThisRecord.ShiftRegisterId, NotificationType.Information)
    )
);
 
I have added the Notify to see if there is an id for the update - & there is.
 
I created a Test button with this code in the OnSelect
 
Patch(
    ShiftRegister,
    LookUp(ShiftRegister, ShiftRegisterId = 3284), 
    { 
        IsApproved: true
    }
)
 
I used the ID from the Notify and it updated the record fine.
 
I have been going round and round in circles and would appreciate any help.
 
Thanks in advance
Categories:
I have the same question (0)
  • MS.Ragavendar Profile Picture
    4,977 Super User 2025 Season 2 on at
    Check the data while updating
    Instead of this 
     Patch(
                ShiftRegister,
                LookUp(ShiftRegister, ShiftRegisterId = ThisRecord.ShiftRegisterId), 
                { 
                    IsApproved: true
                }
            );
    Try This
     
    Patch(
                ShiftRegister,
                LookUp(ShiftRegister, ShiftRegisterId = Value(ThisRecord.ShiftRegisterId)), 
                { 
                    IsApproved: true
                }
            );
     
     
    🏷️ Please tag me @MS.Ragavendar if you still have any queries related to the solution or issue persists.
    Please click Accept as solution if my post helped you solve your issue and help others who will face the similar issue in future.
    ❤️ Please consider giving it a Like, If the approach was useful in other ways.
  • Verified answer
    WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    Try with the As disambiguation operator. Also a Notify inside a ForAll statement is a bit of a waste of time.
    ForAll(
       colShiftReg As _Data,
       If( 
          IsBlank(_Data.ShiftRegisterId), 
          Patch(
             ShiftRegister,
             Defaults(ShiftRegister),
             { 
                SupervisorId: _Data.SupervisorId, 
                DepotId: _Data.DepotId, 
                ShiftDate: SR_dtp_Shift_Date.SelectedDate + Time(Hour(Now()), Minute(Now()), 0),
                ShiftDetailsId: _Data.ShiftDetailsId, 
                OperativeId: _Data.OperativeId, 
                Hours: _Data.Hours, 
                ShiftType: _Data.ShiftType, 
                Enhancement: _Data.Enhancement, 
                Comments: _Data.Comments, 
                ContractId: _Data.ContractId, 
                IsApproved: true, 
                IsDeleted: _Data.IsDeleted, 
                RegisterId: GUID(varRegisterId)
             } 
          ),
          Patch(
             ShiftRegister,
             LookUp(
                ShiftRegister, 
                ShiftRegisterId = _Data.ShiftRegisterId
             ), 
             {IsApproved: true}
          );
          Notify(
             "Patch completed for Id" & _Data.ShiftRegisterId, 
             NotificationType.Information
          )
       )
    );
    
     
    Please click 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 giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • MikeGutty Profile Picture
    25 on at
    WarrenBelz - thank you that has worked - I only had the Notify in to give me an Id to use in my test code have removed it now.
     
    Appreciate your help - thanks

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard