Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Updating a variable after a patch

(0) ShareShare
ReportReport
Posted on by 697

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:
  • Verified answer
    DCHammer Profile Picture
    DCHammer 697 on at
    Re: Updating a variable after a patch

    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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,526

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard