cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IconicAngel
Helper I
Helper I

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

 

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.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (4,693)