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 / Why does this "With"/"...
Power Apps
Unanswered

Why does this "With"/"If" construction fail?

(0) ShareShare
ReportReport
Posted on by 241

Sorry for raising yet another mysterious issue. I'm breaking my head over a problem I'm running into in my app.

 

I'm writing a handler for the 'OnCheck' event of a toggle switch.  I was able to analyze it down to the following simple example: 

UpdateContext({ connectioncheck: Connection.Connected, patch: true } );
With({ name: "Bill" },
 If( connectioncheck,
 With( { something_else: "" },
 If( patch,
 Notify("patching");
 //Patch(Users, Defaults(Users), { 'Full Name': name } );
 ,
 Notify("not patching");
 );
 );
 ,
 Notify("collect");
 //Collect(dummycollection, { fullname: name });
 );
);

This code will not do a lot yet, but is considered correct. 

You will notice I commented out 2 lines. Those are required for the code to actually do what I want. However, when any (or both) of those lines are uncommented, the editor starts throwing errors (mostly simply saying 'The function If has some invalid arguments').

I don't see what's going wrong here. I've used nested "With" constructions in more places in my app and never ran into this problem?

Categories:
I have the same question (0)
  • CarlosFigueira Profile Picture
    on at

    Thank you for reporting this issue; I'll file a bug with the appropriate team to get it fixed.

    Meanwhile, the issue seems that, inside a With statement, the If function is requiring both branches (the "true" branch and the "false" branch) to have the same type, so you can work around this issue by having a dummy value that is returned by it:

    UpdateContext({ connectioncheck: Connection.Connected, patch: true } );
    With({ name: "Bill" },
     If( connectioncheck,
     With( { something_else: "" },
     If( patch,
     Notify("patching");
     Patch(Users, Defaults(Users), { 'Full Name': name } );
     ""
     ,
     Notify("not patching");
     );
     );
     ,
     Notify("collect");
     Collect(dummycollection, { fullname: name });
     "";
     );
    );

    Hope this helps!

  • v-xida-msft Profile Picture
    on at

    Hi @MrNappa ,

    Could you please share a bit more about the error message within your app?

    Could you please show more details about the "Users" data source?

     

    Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. Please consider modify your formula as below:

    UpdateContext({connectioncheck: Connection.Connected, patch: true});
    With(
     {name: "Bill"},
     If(
     connectioncheck,
     With(
     {something_else: ""},
     If(
     patch,
     Notify("patching");Patch(Users, Defaults(Users),{'Full Name': name}),
     Notify("not patching")
     );
     ),
     Notify("collect");Collect(dummycollection, {fullname: name})
     )
    )

    For Patch function in above formula, please check if you have typed proper value for Required field in your Users if there are some Required fields existed in your Users data source.

    Note: If the Users data source is a SP List data source, please make sure you have specified Required field (e.g. Title) from your data source within the '{}' part of the Patch function.

     

    You could consider move above formula from the OnCheck property into the OnChange property of the Toggle control, then check if the same issue would show up.

     

    Also please consider turn on the "Formula-level error management" option within Advanced settings of App settings of your app, then try your formula again, check if the issue is solved.

     

    Best regards,

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