cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mantastg08876
Responsive Resident
Responsive Resident

Having troubles Submitting the canvas app form using OnSelect function with IF condition

Hello, 

 

I have the trouble of finding out why the SubmitForm  formula in a button's OnSelect function is not working in the following code:

OnSelect =
If(
    "ABC" in Type.SelectedItems.Value && IsBlank(Number.Text),
    Set(
        vStatus,
        "ABC"
    ),
             /*Set status to Created*/
                                            Set(
                                                vStatus,
                                                "Created"
                                            );
            
/*set item var for saving information*/
Set(
                varLastSubmitedItem,
                Blank()
            );
            
/*submit form*/
SubmitForm(MT_form)
        )

 This code changes the status as expected, but it seems the function stops working as soon as it is changed because SubmitForm(MT_form) is not executed. Does anyone see any problem in this code? 

1 ACCEPTED SOLUTION

Accepted Solutions
eka24
Super User III
Super User III

You may have to explain further the occurrence of the Conditions, I can count 4 of those.

Meanwhile consider this:

OnSelect =

If("ABC" in Type.SelectedItems.Value && IsBlank(Number.Text),

    Set(  vStatus, "ABC" ),

        /*Set status to Created*/

    Set(vStatus, "Created"));      

/*set item var for saving information*/

Set(varLastSubmitedItem, Blank( );         

/*submit form*/

SubmitForm(MT_form) 

 

I moved the last parenthesis ) from the submit form.

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

View solution in original post

6 REPLIES 6
eka24
Super User III
Super User III

You may have to explain further the occurrence of the Conditions, I can count 4 of those.

Meanwhile consider this:

OnSelect =

If("ABC" in Type.SelectedItems.Value && IsBlank(Number.Text),

    Set(  vStatus, "ABC" ),

        /*Set status to Created*/

    Set(vStatus, "Created"));      

/*set item var for saving information*/

Set(varLastSubmitedItem, Blank( );         

/*submit form*/

SubmitForm(MT_form) 

 

I moved the last parenthesis ) from the submit form.

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

View solution in original post

WarrenBelz
Super User III
Super User III

Hi @mantastg08876 ,

Looking at your code below

If(
   "ABC" in Type.SelectedItems.Value && IsBlank(Number.Text),
   Set(
      vStatus,
      "ABC"
   ),
   Set(
      vStatus,
      "Created"
   );
   Set(
      LastSubmitedItem,
      Blank()
   );
   SubmitForm(MT_form)
)

If the first test fails, it should set the two Variables (vStatus to "Created" and LastSubmitItem to Blank() and then submit the form.

Are you saying the first two succeed and the last fails?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

hi @WarrenBelz , many thanks for your reply. Yes, that is what is happening: if the first test succeeds, vStatus is set to "ABC", but LastSubmitItem is not set to blank and the SubmitForm(MT_form) is not executed.

I have edited the code like this:

If(
"ABC" in Type.SelectedItems.Value && IsBlank(Number.Text),
Set(
vStatus,
"ABC"
) && SubmitForm(MT_form),
Set(
vStatus,
"Created"
);
Set(
LastSubmitedItem,
Blank()
);
SubmitForm(MT_form)
)


This code submits the MT_form when the first test is successful. 

mantastg08876
Responsive Resident
Responsive Resident

Hi, @eka24 , 

It worked. I have used the parenthesis in the wrong place. I wanted to have one condition.

Never mind - you have solved it. What I posted was also valid, but I replaced the comma with a semi-colon.

Noted. Thank you. The problem apparently was that I didn't close the IF function after else statement. If(condition, true, false). I missed the parenthesis after false 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (79,987)