web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / if inside switch throw...
Power Apps
Unanswered

if inside switch throwing error

(1) ShareShare
ReportReport
Posted on by 48

Hi All,

 

I'm trying the below code, but idk why it is throwing error

Switch(
 vStatus,
 "complete",
 If(
 IsBlank(
 LookUp(
 delivery,
 ID = vSelectedID,
 Version = "completed"
 )
 ),
 Patch(
 delivery,
 {ID: vSelectedID},
 {Status: "completed"}
 ),
 Notify("already order is completed",NotificationType.Error)
 ),
 "finalize",
 Patch(
 delivery,
 {ID: vSelectedID},
 {Status: "finalized"}
 )
)

 

if i'm writing the if condition part outside of switch. it is fine.

Categories:
I have the same question (0)
  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    I think that the problem is missing you a default. Not the if...

     

    Switch(
    vStatus,
    "complete",
    If(
    IsBlank(
    LookUp(
    delivery,
    ID = vSelectedID,
    Version = "completed"
    )
    ),
    Patch(
    delivery,
    {ID: vSelectedID},
    {Status: "completed"}
    ),
    Notify("already order is completed",NotificationType.Error)
    ),
    Patch(
    delivery,
    {ID: vSelectedID},
    {Status: "finalized"}
    )
    )

  • Unkn0wn Profile Picture
    48 on at

    @Nogueira1306 

    Hi I've tried the same as well. but no luck i dont think its because of default

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Show me the error

  • Unkn0wn Profile Picture
    48 on at

    @Nogueira1306 

    Unkn0wn_0-1628770259181.png

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at
    If(
     IsEmpty(
     LookUp(
     delivery,
     ID = vSelectedID,
     Version = "completed"
     )
     ),
     Patch(
     delivery,
     {ID: vSelectedID},
     {Status: "completed"}
     )
  • Unkn0wn Profile Picture
    48 on at

    @Nogueira1306  thanks for response

    tried with isempty & isblank with filter as well but no luck

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Unkn0wn,

    The issue stays?

    I have a test on my side, and I found key to this issue is indeed the invalid argument.

    The If() statement inside the Switch() returns a record if the condition is true, but it will display a banner message if the condition is false, which is not a record of data type. In addition, the second formula to be evaluated for matching returns a records, that's why the error message said that it expects a record value. You should keep all the returned result is a record in the If() statement.

    I personally don't recommend mixing Switch() and If() in the same function unless you keep all the returned data type same.

    On your side, I suggest that you could replace the Switch() with the If() as below:

    If(
     vStatus="complete",// Use the If()
     If(
     IsBlank(
     LookUp(
     delivery,
     ID = vSelectedID,
     Version = "completed"
     )
     ),
     Patch(
     delivery,
     {ID: vSelectedID},
     {Status: "completed"}
     ),
     Notify("already order is completed",NotificationType.Error)
     ),
     vStatus="finalize", 
     Patch(
     delivery,
     {ID: vSelectedID},
     {Status: "finalized"}
     )
    )

     

     

     

     

     Hope this could help you.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard