cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SeanTambling
Level: Powered On

What is the syntax for writing an IF statement for the "Items" control of a form

I have a form that I would like to be able to populate from any 1 of 3 different galleries.

I guess i should start at the beginning.

Screen1 is the Welcome Screen and has 3 buttons. Each button navigates to 1 of 3 different screens. Each of those screens has a gallery. All of the galleries are using the same SQL table and each of the galleries are filtered differently depended on the screen that was navigated to.

 

What i would like to do is, when an Item is selected from any 1 of the 3 different galleries aformentioned, the user is navigated to a form screen. The form currently has its "Item" control set to Item=MyGroupGallery.Selected. This works like you would expect. 

 

Is it possible to change the "Item" control to use an IF statement? I know this example won't work, but is it possible to change the syntax so that it will work? 

Example1: Item=MyGroupGallery.Selected Or TerritoryGallery.Selected Or AllSearchGallery.Selected

Example2: Item= If (MyGroupBtn.Pressed, MyGroupGallery.Selected, Or TerritoryBtn.Pressed, TerritoryGallery.Selected Or AllSearchBtn.Pressed, AllSearchGallery.Selected)

 

This last Example doesn't give me an error, but it's also not working:

Example3: Item= If(MyGroupBttn.Pressed, MyGroupGallery.Selected,
TerritoryBttn.Pressed, TerritoryGallery.Selected,
SearchAllBttn.Pressed, AllSearchGallery.Selected)

For this example, Regardless of which button was pressed on the home screen and an Item selected on its respective gallery screen, the form loads with a notice "No Item to display" 

 

So, Is it at all possible or do I need to create 2 more form screens to accomodate the other 2 galleries?

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

So lets assume there is a key field in the database called ID (it will work with anything that uniquely identifies the record).  Then in the button that does the navigation do the following:

Set(KeyID, MyGroupGallery.Selected.ID)

Each button will use the same KeyID variable, but a different gallery.  Now in the form you set item equal to 

Lookup(datasource, ID = KeyID)


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

So the buttons in the Gallery screen should just navigate to the correct gallery screen.  Then the button in each gallery screen sets the variable to be equal to the selected item in that gallery and then navigate to the form screen.  YOur code showed you setting the variable when you navigate to the three different gallery screens.  You have to wait till you select something on one of those screens before you set the variable.  So its on exit from the gallery screens that you set the variable, not on navigating to the gallery screens.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

13 REPLIES 13
Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

Can I offer an alternative way to do it.  when you navigate from one of the screens to the Edit screen save the KEY of the selected record in a variable.  Then set the form equal to a Lookup against the datasource on that key.  That way you can use the same form, but 3 different originating screens without getting into messy If statements.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
SeanTambling
Level: Powered On

Re: What is the syntax for writing an IF statement for the "Items" control of a form

@Pstork1 
I like this idea, but i'm still so new, that i could use help understanding and writing the code for the variable.

Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

So lets assume there is a key field in the database called ID (it will work with anything that uniquely identifies the record).  Then in the button that does the navigation do the following:

Set(KeyID, MyGroupGallery.Selected.ID)

Each button will use the same KeyID variable, but a different gallery.  Now in the form you set item equal to 

Lookup(datasource, ID = KeyID)


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

SeanTambling
Level: Powered On

Re: What is the syntax for writing an IF statement for the "Items" control of a form


@Pstork1 wrote:

So lets assume there is a key field in the database called ID (it will work with anything that uniquely identifies the record).  Then in the button that does the navigation do the following:

Set(KeyID, MyGroupGallery.Selected.ID)

Each button will use the same KeyID variable, but a different gallery.  Now in the form you set item equal to 

Lookup(datasource, ID = KeyID)

I guess i should do the Set(KeyID, MyGroupGallery.Selected.ID) in the OnSelect control? Just making sure.

SeanTambling
Level: Powered On

Re: What is the syntax for writing an IF statement for the "Items" control of a form

Thank you so much! That worked like a charm! I've learned something new and i can use this for other features i want to add to the app.

SeanTambling
Level: Powered On

Re: What is the syntax for writing an IF statement for the "Items" control of a form

@Pstork1 

The Variable works, and it does eventually Navigate. This is a screenshot of the 3 variables of your suggestion that i'm using.

VariableMakesAppSlow.png

There seems to be some problem, or maybe its just a quirk in using a variable like this.

When i start from screen 1 and screen 2 has the gallery filtered the way i want it to and then i click an item in the gallery, the 3rd screen loads but the data for the form doesn't.

VariableMakesAppSlowGettingData.png

You might have to squint to see the wording in the red circled area, but it just sits there saying "Getting your data"  and it never loads. I've let it sit there for 30min now waiting for it to load and it hasn't. To get the data to load into the form, you have to go back to the welcome screen, click the button to a respective gallery, select an item from the gallery and then the form will load. And sometimes, if you select an item that was different than the first time you, the form will load with data from the first time when an item was selected from the gallery. Its very odd behavior.

 

Any ideas?

Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

Sorry, I missunderstood your specifics.  I thought you had three galleries to pick from but the same final screen.  Since your navigate statements are all different I taek that isn't the case.  If you have three galleries and three screens to navigate to you really don't need a variable at all.  You can just hard code the screens by matching them to the right gallery.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
SeanTambling
Level: Powered On

Re: What is the syntax for writing an IF statement for the "Items" control of a form

I'm probably making this way more complicated than i need to, but i couldn't figure out any other way to accomplish what i wanted, than to do it this way.

I have one SQL datasource

Order of screens and buttons:

Screen1 named WelcomeScreen:

WelcomeScreenButtons.png

I'm really very new at this and so, i created a new screen for each of the buttons listed in the above image. Each screen has the same data source for the gallery on that respective screen. I thought the galleries had to have different names for each screen.

The 2nd, 3rd, and 4th screens all filter the same datasource differently. I know i could have put the buttons on one page and wanted to but I was told to do it this way. 

Instead of creating 3 seperate form screens (1 for each of the gallery screens to navigate to) i was hoping to have one Form screen that the gallery screens navigate to. Your variable code does accomplish this. But for some reason there is a hicup somewhere along the way and the data doesn't load on the first try. I have to navigate back to the welcome screen and then chose a filter button that navigates to a gallery screen that lets me select an item, that navigates to 1 form screen.

 

I won't be offended if you tell me i'm doing it all wrong, so please tell me straight. I just want this to all work.

 

Thank you, really..., thank you for helping me this far. Please don't give up on me, i will get this before too long.

 

Dual Super User
Dual Super User

Re: What is the syntax for writing an IF statement for the "Items" control of a form

I don't think you are doing anything wrong.  I'm just trying to wrap my head around the design.  You said"Instead of creating 3 seperate form screens (1 for each of the gallery screens to navigate to) i was hoping to have one Form screen that the gallery screens navigate to." That's what I thought you intended originally. But the screenshot in your last post showed a navigation function on the buttons that navigated to three different screens.  If you were going to have one form screen then I would assume those navigates would all be to the same screen.  So i thought you were headed for something like this.

 

welcome screen with three buttons -> Navigate to a specific gallery screen based on the button pressed -> set a variable based on the selected record and navigate to single from screen where variable is used to set Items in form.

 

So one welcome screen - three gallery screens - one form screen.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (5,954)