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 / Setting ComboBox defau...
Power Apps
Answered

Setting ComboBox default where Items are three columns from an SQL table

(0) ShareShare
ReportReport
Posted on by 51

I have an edit form that has a ComboBox for selecting a State and entering a password. The SQL table that populates the Combobox looks like this:

workerState    state     password
T                     TAS       1234
V                     VIC       4567

 

If the user sets the State and Password correctly in their first login, then the state and password are saved on the local device.


ClearCollect(currentState, cmbState.Selected);
ClearCollect(statePassword,txtStatePassword.Text);
SaveData(currentState,"savedLastState");
SaveData(statePassword,"savedStatePassword");


In the Powerapps App OnStart event, I have:


/*load last state and password*/
LoadData(currentState,"savedLastState", true);
LoadData(statePassword,"savedStatePassword", true);


Then I test if the last selected state and it's password matches with the State and password from the newly downloaded SQL states table.

 

/*now check if state and password combo are correct*/
Set(statePasswordAccepted,Text(First(Filter(states, workerState = Left(First(currentState).state,1))).password)=First(statePassword).Value);

If the local state and password do not match with the SQL version I clear the state and password collections:

If(statePasswordAccepted=false,
Clear(currentState);
Clear(statePassword);
);

 

In the DefaultSelectedItems property, I have the following:

 

If(statePasswordAccepted,First(currentState))

 

This works correctly on the form when the user opens it the second time. The last state selected looks like it is selected and if the user just presses the Open button the app moves to the next form. BUT if the user clicks on the State's Combobox the screen goes Black. The Powerapp is still running but nothing is showing. If I press the back arrow on my mobile device, the app asks if I would like to close the Powerapp.

 

I thought it could be that the Combobox OnSelect code could be creating the issue so I deleted it but the issue continued and I still receiving the black screen of death when I selected the States Combobox.

 

Any thought would be greatly received.

Categories:
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @IconicAngel ,

    Could you please share a screenshot about your issue within your ComboBox?

    Do you type Exit() function within your ComboBox OnSelect property?

    Further, could you please show more details about the formula you typed within the Items property of the State ComboBox?

     

    Based on the formula you provided, I could not find any syntax error with it. You could also consider modify your formula as below:

    ClearCollect(currentState, cmbState.Selected.state); // Modify formula here
    ClearCollect(statePassword,txtStatePassword.Text);
    SaveData(currentState,"savedLastState");
    SaveData(statePassword,"savedStatePassword");

     

    /*now check if state and password combo are correct*/

    Set(
     statePasswordAccepted,
     LookUp(states, workerState = Left(First(currentState).Value,1)).password = First(statePassword).Value // Modify formula here
    );

     

    set the DefaultSelectedItems property of the State ComboBox to following:

    If(
     statePasswordAccepted,
     {
     state: First(currentState).Value
     }
    )

    then re-publish your app, check if the issue is solved.

     

    Best regards,

  • IconicAngel Profile Picture
    51 on at

    Thank @v-xida-msft 

     

    Your post helped heaps. I didn't make the change in the following:

     

     

    ClearCollect(currentState, cmbState.Selected.state); // Modify formula here
    ClearCollect(statePassword,txtStatePassword.Text);
    SaveData(currentState,"savedLastState");
    SaveData(statePassword,"savedStatePassword");

     

     

     

    I still needed to pull the password out of the State record and use it in the following (I did change .Value to .state)

     

    Set(
     statePasswordAccepted,
     LookUp(states, workerState = Left(First(currentState).Value,1)).password = First(statePassword).Value // Modify formula here
    );

     

     

     

    But what your post pointed to was that I was populating the ComboBox with a set of fields. I changed the items list to the following:

     

     

    states.state

     

     

     

    When the user selected a State from the ComboBox the event filtered and ClearCollected the selected state record as currentState. This meant that all the current State fields would be available to use throughout the app.

     

     

    ClearCollect(currentState, Filter(states, state = cmbState.Selected.state));

     

     

     

    I also changed the DefaultSelecteItems property as you suggested:

     

     

    although I changed .Value to .state seeing currentState contained multiple fields:

     

     

    If(statePasswordAccepted,{state: First(currentState).state})

     

     

    My app now works as dreamed. Thanks again.

     

  • IconicAngel Profile Picture
    51 on at

    Thank @v-xida-msft 

     

    Your post helped heaps. I didn't make the change in the following:

     

     

    ClearCollect(currentState, cmbState.Selected.state); // Modify formula here
    ClearCollect(statePassword,txtStatePassword.Text);
    SaveData(currentState,"savedLastState");
    SaveData(statePassword,"savedStatePassword");

     

     

    I still needed to pull the password out of the State record and use it in the following (I did change .Value to .state)

     

     

    Set(
     statePasswordAccepted,
     LookUp(states, workerState = Left(First(currentState).Value,1)).password = First(statePassword).Value // Modify formula here
    );

     

     

    But what your post pointed to was that I was populating the ComboBox with a set of fields. I changed the items list to the following:

     

     

    states.state

     

     

    When the user selected a State from the ComboBox the event filtered and ClearCollected the selected state record as currentState. This meant that all the current State fields would be available to use throughout the app.

     

     

    ClearCollect(currentState, Filter(states, state = cmbState.Selected.state));

     

     

    I also changed the DefaultSelecteItems property as you suggested:

     

     

    If(
     statePasswordAccepted,
     {
     state: First(currentState).Value
     }
    )

     

     

    although I changed .Value to .state seeing currentState contained multiple fields:

     

     

    If(statePasswordAccepted,{state: First(currentState).state})

     

     

    My app now works as dreamed. Thanks again.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 221 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 120

Last 30 days Overall leaderboard