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 / Updating a variable af...
Power Apps
Answered

Updating a variable after a patch

(0) ShareShare
ReportReport
Posted on by 716 Moderator

So I searched and read and tested and then repeated and now here I am.

 

I've seen multiple posts that suggest my Set statement should be valid but throws errors in the Editor so there is clearly something wrong in the syntax. My suspicion is that I can't put a Set inside of an If or I have a referential problem because I'm trying to patch a record that I'm also trying to search for within the If.

Here is the logic that sucessfully completes but causes varItem to continue to hold the old values. Specifically Approval_Level which is used to affect visibility of controls:

 

If(
 varNewApprovalLevel <> varItem.Approval_Level,
 Patch(
 'SPIFF - Requests',// The target data source (e.g., SharePoint list)
 LookUp(
 'SPIFF - Requests',
 ID = varItem.ID
 ),// Identify the specific record
 {Approval_Level: varNewApprovalLevel
 // Update or set the value of Approval_Level column
// Add more columns and values as needed
}
 );
 UpdateContext ({varNewApprovalLevel: Blank()})
);

 

 Here is my unsuccessful attempt at inserting a Set statement into this so that varItem updates:

 

If(
 varNewApprovalLevel <> varItem.Approval_Level,
 Set(varItem,
 Patch(
 'SPIFF - Requests',// The target data source (e.g., SharePoint list)
 LookUp(
 'SPIFF - Requests',
 ID = varItem.ID
 ),// Identify the specific record
 {Approval_Level: varNewApprovalLevel
 // Update or set the value of Approval_Level column
// Add more columns and values as needed
}
 );
 UpdateContext ({varNewApprovalLevel: Blank()})
));

 

I think it's wrong because I'm actually trying to set varItem equal to just the patch value itself and not the record that's being patched but can't figure out the syntax to do it correctly.

Categories:
I have the same question (0)
  • Verified answer
    DCHammer Profile Picture
    716 Moderator on at

    This is what I finally did. I separated the Edit icon from the save icon and use a pre-existing variable that controls a containers visibility allowing for record modification to turn the Edit and Save icons on and off.

    Then I put the update logic only on the Save icon to simplify the code.

    This is the Save icons OnSelect:

    Set(
     varGalEdit,
     false
    );
    Refresh('SPIFF - Approvals');
    If(
     CountRows(
     Filter(
     'SPIFF - Approvers',
     Approve_Level = varItem.Approval_Level
     )
     ) = CountRows(
     Filter(
     'SPIFF - Approvals',
     Approve_Level = varItem.Approval_Level && PositionID = varItem.ID
     )
     ),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 1}),
     UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 0})
    );
    If(
     varNewApprovalLevel <> varItem.Approval_Level,
     Patch(
     'SPIFF - Requests',// The target data source (e.g., SharePoint list)
     LookUp(
     'SPIFF - Requests',
     ID = varItem.ID
     ),// Identify the specific record
     {Approval_Level: varNewApprovalLevel
     // Update or set the value of Approval_Level column
    // Add more columns and values as needed
    }
     );
     UpdateContext ({varNewApprovalLevel: Blank()});
     Set(
     varItem,
     LookUp(
     'SPIFF - Requests',
     ID = varItem.ID
     );
     )
    );
    Refresh('SPIFF - Requests');

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
Kalathiya Profile Picture

Kalathiya 400

#2
WarrenBelz Profile Picture

WarrenBelz 348 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 315 Super User 2025 Season 2

Last 30 days Overall leaderboard