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 Apps
Unanswered

If Else Patch

(0) ShareShare
ReportReport
Posted on by 156

I'm trying to patch a certain data into my Sharepoint list to update the data that's inside the table. It's a leave app that's currently lacking the ability to update it's Sharepoint List. This is the requirements that I need to meet, I need to update the Used data field by the Duration that the user has selected. Above that, I need to match the type of leave that they have chosen, whether if it is Medical, Maternity or Annual (Anything besides Medical/Maternity will be added to the annual Used column). Is there a possibility where I match the user's name as well? The following is the current code:

If(
 DataCardValue15.Selected.Value= "Medical",
 Patch(
 'EMP Leave Quota',
 {Title:Text(Self.LastSubmit.'Employee No')},
 {Used:0}
 ),
 DataCardValue15.Selected.Value= "Maternity",
 Patch(
 'EMP Leave Quota',
 {Title:Text(Self.LastSubmit.'Employee No')},
 {Used:Value(DataCardValue24.Text)}
 ),
 Patch(
 'EMP Leave Quota',
 {Title:Text(Self.LastSubmit.'Employee No')},
 {Used:Value(DataCardValue24.Text)}
 )
);

 DataCardValue15 is the selection box and DataCardValue24 is the Duration column in the app. 

Screenshot 2020-12-31 at 12.22.55 PM.png
Screenshot 2020-12-31 at 12.22.18 PM.png
Screenshot 2020-12-31 at 11.36.44 AM.png
Categories:
I have the same question (0)
  • FabianAckeret Profile Picture
    975 on at

    Hi @gimar01 

     

    Try this:

    If(
     DataCardValue15.Selected.Value <> "Medical" ||
     DataCardValue15.Selected.Value <> "Maternity",
     Patch(
     'EMP Leave Quota',
     {Title:Self.LastSubmit.ID},
     {Used:Value(DataCardValue24.Text)}
     ),
     Patch(
     'EMP Leave Quota',
     {ID:Self.LastSubmit.ID},
     {Used:0}
     )
    );

     

    I assume that before patching, you submitted that form already. That's why I'm using LastSubmit.ID. If you don't submit the form before patching, make sure to insert the right ID there instead.

     

    I hope this helps

    Kind regards,

     

  • gimar01 Profile Picture
    156 on at

    The code is currently running onSuccess of the form being submitted.

    This patch does work but it doesn't update the record instead it creates a new record entirely. Don't mind me asking but is there a way that I can use power automate to direct the supervisor to just a line of record for them to update instead of using this method as I'm continuing on another person's project which means that I can't explain well the origins of the code. 

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @gimar01 ,

     

    Could you tell me:

    • Do you want to update a record instead of creating a record?

     

    If my assumption is correct, the point is the parameters of the patch() function.

    The second parameter of the patch() function is the record that needs to be updated.

    Usually we can use the lookup() function or the first(filter()) function to find the record that needs to be updated.

    Hope this link will help you.Here 

     

    So, you could try this:

    If(
    
     DataCardValue15.Selected.Value= "Medical",
    
     Patch(
    
     'EMP Leave Quota',
    
     LookUp(your table,Title= Text(Self.LastSubmit.'Employee No')),
    
     {Used:0}
    
     )
    
    …………………
    
    ……….

     

    Best Regards,

    Wearsky

    If my post helps, then please consider Accept it as the solution to help others. Thanks.

  • gimar01 Profile Picture
    156 on at

    There are 2 Sharepoint List that are currently in use, one for keeping the data of the duration and the other for keeping the Used dates. And yes, I would like to update the data instead of creating a new one, it's supposed to add on to the concurrent used amount based on the type of leave and the persons name. Is there a possibility of me matching them both? So I can get the right data.

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @gimar01 ,

     

    So could you tell me:

    Does my test formula meet your needs?

     

    If it does not fully meet your needs, please tell me what else you need.

    If you have any doubts about the formula, please let me know.

     

    Best Regards,

    Wearsky

    If my post helps, then please consider Accept it as the solution to help others. Thanks.

  • gimar01 Profile Picture
    156 on at

    I'm trying to add on to the Used date of the user. 
    Take this situation for an example:
    A user keys in the days they are taking their leave for and the type of leave that they are taking. The system add the duration amount to the Used column in another sharepoint list which is matched towards their type of leave and their names which they are entitled to.
    Is there a way to use the current code that i've got to make this function functional? A side note, the lookup code you gave me returns an error when I put it in the textbox. The whole things runs when the app is OnSuccess.

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @gimar01 ,

     

    I am confused about your question.

    Firstly, do you want to execute the formula on the onsuccess property of edit form control?

    Secondly, could you share your formula with me?

     

    Thanks for providing more information.

    Best Regards,

    Wearsky

  • gimar01 Profile Picture
    156 on at

    The whole code runs on a OnSuccess of the form named Form3, at the end when Form3 is submitted. When successful it proceeds with all of the following actions.

    If(
     DataCardValue15.Selected.Value= "Medical" ||
     DataCardValue15.Selected.Value= "Maternity",
     Patch(
     'EMP Leave Quota',
     {Used:Value(DataCardValue24.Text)}
     ),
     Patch(
     'EMP Leave Quota',
     {Used:Value(DataCardValue24.Text)}
     )
    );
    Patch(
     eLeaveApp,
     {ID:Self.LastSubmit.ID},
     Form4_1.Updates,
     Form2.Updates,
     Form4.Updates,
     {DateApply: Now()}
    );
    Navigate(Review);
    ResetForm(Form3);
    ResetForm(Form2);
    ResetForm(Form4_1);
    ResetForm(Form4);
    UpdateContext({showAlert:false})

    I was playing around with the code to see if I was able to adjust it and make it work.

    Screenshot 2021-01-05 at 11.58.06 AM.png
  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @gimar01 ,

     

    I suggest that you could learn the syntax of patch() funcition. Your formula miss BaseRecord.

    v-xiaochen-msft_0-1609825367734.png

     

    v-xiaochen-msft_1-1609825367737.png

     

     

    Best Regards,

    Wearsky

     

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @gimar01 ,

     

    Could you tell me:
    Has the problem been solved?
    Is there anything else I can help?

     

    Best Regards,

    Wearsky

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#2
11manish Profile Picture

11manish 205 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard