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 / Need help with Patch f...
Power Apps
Answered

Need help with Patch function that adds 1 to the value already present in the column and updates it with the new value

(0) ShareShare
ReportReport
Posted on by 85

Hi,

 

I need help with patching a database column when apply button is clicked.

Scenario is very simple but I am unable to work past the error.

I have two tables.

Table 1: Teachers(it has teacher details and one of the fields in question: Seats_Remaining)

Table 2: Tuition(it has the teacher and student details and the status of the tuition)

 

Scenario:

Student chooses a teacher and then clicks on the 'Apply' button for tuition classes.

Teacher goes to his/her/their profile and checks students applied section. It has two buttons, approve or reject.

When the teacher clicks on 'Approve' button, the patch function should run and update the above two tables with required values.

Update Table 1 against that teacher's entry and add 1 to the value already present in the 'seats remaining' column.

Then update Table 2 against the tuition entry, update the status of the tuition to ongoing.

Rejecting would just change the status to rejected and that's it.

Code that I wrote for the OnSelect property of the accept button is as follows:

Patch
(
'Tuition',
LookUp('Tuition', ID=ThisItem.ID),
{
Tuition_Status: {Value: "Ongoing"}
}
);
Patch
(
'Teachers',
LookUp('Teachers', EID= ThisItem.Teacher_ID),
{
Seats_Remaining: {Value: Seats_Remaining+1}
}
)

This is not working. I have tried a few other permutation combination. I have updated a label with the seats_remaining column data from table Teachers, and then I am adding 1 to the label.text and then storing it in seats.
Nothing works.
Suggestions please.

 

Categories:
I have the same question (0)
  • Verified answer
    Pstork1 Profile Picture
    69,573 Most Valuable Professional on at

    The key here would be to save the current Seats_Remaining value to a variable and then update the variable's value in the patch.

    Set(currentSeats, LookUp('Teachers', EID= ThisItem.Mentee_EID).Seats_Remaining);
    Patch
    (
    'Tuition',
    LookUp('Tuition', ID=ThisItem.ID),
    {
    Tuition_Status: {Value: "Ongoing"}
    }
    );
    Patch
    (
    'Teachers',
    LookUp('Teachers', EID= ThisItem.Mentee_EID),
    {
    Seats_Remaining: {Value: currentSeats + 1}
    }
    )
  • AD1990 Profile Picture
    85 on at

    @Pstork1 
    This worked with a little correction.

    And apologies for having a typo in the column name in my original question.

     

    I set the below variable to pick up data from previous screen.
    Set(currentSeats, LookUp('Teachers', EID= ThisItem.Teacher_ID).Seats_Remaining)
    
    On the approve button:
    Patch
    (
    'Tuition',
    LookUp('Tuition', ID=ThisItem.ID),
    {
    Tuition_Status: {Value: "Ongoing"}
    }
    );
    Patch
    (
    'Teachers',
    LookUp('Teachers', EID= ThisItem.Teacher_ID),
    {
    Seats_Remaining: currentSeats + 1
    }
    )

     

    The 

    Seats_Remaining: {Value: currentSeats + 1}

    was operating with a record and hence it was giving the incompatible type error.

    My bad for mentioning the column data type was just plain text. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#2
11manish Profile Picture

11manish 192

#3
Valantis Profile Picture

Valantis 128

Last 30 days Overall leaderboard