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 / trying to use If(true,...
Power Apps
Answered

trying to use If(true, then do this, else do this) does not work with Switch and Patch ?

(0) ShareShare
ReportReport
Posted on by 166

I wanted to write the following code in the format If(true, then do this, else do this).  However this is not working (something to do with the Switch or the Patch ?).  Here is the only way i could get the code to work:

 

Switch(locbtnSubmit,
    "Submit",
          If(IsBlank(recRevDoc.SubmitComments),
               UpdateContext({locWarning:"Comments are required. Please update comments"})

           );

          If(!IsBlank(recRevDoc.SubmitComments),
          Patch(
               jctnReviewersDocRevs,
              LookUp(jctnReviewersDocRevs,new_jctnreviewersdocrevid = recRevDocRevsCurr.new_jctnreviewersdocrevid),
              {ReviewDateStart: Now()}
             )
         )
     ,

 

 

I tried the following and it works 

 

Switch(locbtnSubmit,
    "Submit",

          If(IsBlank(recRevDocRevsCurr.SubmitComments),
                 UpdateContext({locIssueDocWarning:"Comments are required. Please update comments"}),
                 UpdateContext({a:"a"})

          );

 

But for some reason this does not work as soon as I use the Patch command with the If...

 

Any idea what i am doing wrong

Regards

Dave

 

Categories:
  • Verified answer
    Daved1 Profile Picture
    166 on at

    I am not sure what i did wrong, but got it to work

     

    I had to write the If statement outside of the Switch, and got it to work.

     

    THen I copied the code back into the Switch, and now it works.  

     

    Not sure what happened. 

     

    Dave

     

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
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard