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 / Button OnSelect, is it...
Power Apps
Answered

Button OnSelect, is it possible to use the Patch condition within IF Statement

(0) ShareShare
ReportReport
Posted on by 182

Power App Button OnSelect, is it possible to use the Patch condition within IF Statement

If(
ThisItem.ID = "",
Patch Function Insert (New) Command,
Patch Function Update Command

);

Categories:
  • schuess3 Profile Picture
    353 on at

    Hey @Sajith ,

     

    Yes, in concept, it is totally acceptable to use a Patch() function inside of an If() function.

     

    Are you having problems? if so, can you provide the actual code?

     

    matt

  • Abhilash_Swain Profile Picture
    901 on at

    @Sajith  yes patch will work with a combination of conditional statements like If.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Sajith 

    Instead of the process you are attempting, consider the following:

     

    For updating an existing record or creating a new record:

     

    Patch(dataSource,
     Coalesce(LookUp(dataSource, ID=ThisItem.ID), Defaults(dataSource)),
     { ... record info...}
    )

     

    The above will lookup the record and if it exists, it will be patched, if not, then it will create a new record.

     

    Also using the collect function instead:

     

    Collect(dataSource,
     {ID: ThisItem.ID,
     ...the rest of the record...}
    )

     

    The above will create a new record if ID is blank, otherwise, it will update the record with the ID provided.

     

    I hope this is helpful for you. 

  • Powerplatform01 Profile Picture
    386 on at

    Yes you can use multiple patch with in if statement.

    You can use patch with in nested if also.

     For more function of patch watch below video..

    https://youtu.be/w2I9ST1FeKw

    Also request you to please subscribe it.🙏

  • Abhilash_Swain Profile Picture
    901 on at

    As an alternative, to patch, you can use UpdateIf.  It will loop thru the collection based on your condition.

    Example:- 

    IDColorPriority
    1RedH
    2Blue 
    3Green 
    4RedH
    5Green 

    UpdateIf(IdentifyIssue,Color ="Red",{Priority :"H"})

    Hope it will be useful .

    Thanks

    Abhi

  • Sajith Profile Picture
    182 on at

    Yes. My code is not working. Please  find  below my code. 

     

    If(
    ThisItem.ID="",
    Patch(
    dataSource,
    Defaults(dataSource),
    {MeetingInitiationTimeStamp: Text(Now())},
    frmdataSource.Updates;
    );
    ,
    Patch(
    dataSource,
    First(
    Filter(
    dataSource,
    ID = vGlobalID
    )
    ),
    {MeetingInitiationTimeStamp:Text(Now())},
    frmdataSource.Updates;
    );

    );

  • Sajith Profile Picture
    182 on at

    Please suggest the best way how it can be achieved. 

    The below code is not working.  

     

    If(
    ThisItem.ID="",
    Patch(
    dataSource,
    Defaults(dataSource),
    {MeetingInitiationTimeStamp: Text(Now())},
    frmdataSource.Updates;
    );
    ,
    Patch(
    dataSource,
    First(
    Filter(
    dataSource,
    ID = vGlobalID
    )
    ),
    {MeetingInitiationTimeStamp:Text(Now())},
    frmdataSource.Updates;
    );

    );

  • Verified answer
    Abhilash_Swain Profile Picture
    901 on at

    Please try with DateTimeValue(Now()) and check.

  • Sajith Profile Picture
    182 on at

    Thanks for your guidance.

    This worked - MeetingInitiationTimeStamp:DateTimeValue(Text(Now()))

    Also there was an issue in my if condition.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 360 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 325

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard