cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

resetting Combo box issues

Hi All,
I have developed a PowerApps list customized form for creation of "suppliers" on SharePoint. Since the form has too many fields, I have divided it into sections. 
 
Each section is on a different screen with edit forms. data on each screen can be saved and user can exit. 
Or user can goto last tab = Review & Submit where we perform the validation of mandatory fields + ability to finally submit the form. 
 
Everything is working in proper way leaving 2 fields on the section B: Service Type & Product type. 
 
These are lookup columns showing the title field from another master list.  
 
On screen B, on change of the Direct Indirect combobox on top, these Service type & Product type comboboxes must be set to blank. 
 
Currently I have tried the below approaches: 
1) OnSelect of  Direct Indirect combobox, Set(resetvar, true);
    DefaultSelectedItems property of  Service Type & Product type: If(resetvar,{},LookUp(SupplierDetails,ID=lastSubmitID,ProductType2)) 
   Did not work. 
2)  OnSelect of  Direct Indirect combobox, Set(resetvar, true);  Set(resetvar, false);
     DefaultSelectedItems property of  Service Type & Product type: If(resetvar,{},LookUp(SupplierDetails,ID=lastSubmitID,ProductType2)) 
    Reset property of  Service Type & Product type: resetvar
    Did not work as it always goes to the false part of the  DefaultSelectedItems and shows currently saved value
3)  OnSelect of  Direct Indirect combobox (DataCardValue54), 
     If(DataCardValue54.Selected.Value<>suppType,Set(resetvar,true);UpdateContext({suppType:DataCardValue54.Selected.Value})) 
    Other things same as above but this works only on the screen B, once we save data and navigate back to screen B, it does not work. 
 
Please suggest some solution on this.
1 ACCEPTED SOLUTION

Accepted Solutions

The only way I know to set a lookup field to a blank value through a Patch is to set its value to:

{Id: -1, Value: Blank()}

So I would suggest that in your Patch operation, you do something like this:

Patch(
    <your datasource>,
    <your record>,
    {
        ...
        <your ServiceType lookup field>: If(IsBlank(DataCardValueServiceType.Selected), {Id: -1, Value: Blank()}, DataCardValueSErviceType.Selected)
        ...
    }
)

Also, one important thing... When you want to set the current (or default) value of a lookup field in a form, consider what's in your combo box Items property as the datasource where you should look for the value to set.

Meaning, if you have a lookup field where the DataCardValueXXX.Items is this...

Choices(<your datasource>.<your lookup field>)

...make sure that you set its current (or default) value doing this in the DefaultSelectedItems property:

LookUp(Choices(<your datasource>.<your lookup field>), Id=<an id>)
-or-
LookUp(Choices(<your datasource>.<your lookup field>), Value=<a value>)

Do not do a lookup to the lookup list as the result will have a different structure than the one provided by the Choices function.

That is a good practice to remember...

View solution in original post

6 REPLIES 6
R3dKap
Super User
Super User

Hi @Anonymous,

If I summarize your need: changing the value of the Direct/Indirect combo box should set the ServiceType and ProductType combo boxes to blank. Right? Or do you need to blank them out only for specific values from Direct/Indirect?

Also, if I'm correct, since your ServiceType and ProductType fields are lookups, their respective Items property should look like this: Choices(<your datasource>.<the field>). Right?

Anonymous
Not applicable

Hi R3dKap

yes I need to set them blank on change of the value in Direct/Indirect combo box. 

Depending on the value ("Direct" or "Indirect") the Items property of below comboboxes shall filter the related items from lookup list. For that, I am using this in the Items property: 

If(DataCardValue54.Selected.Value="Direct",
SortByColumns(Filter(ItemCategoryMaster,And(DirectInd.Value="Direct",ProdOrServ.Value="Service")),"Title",Ascending),
SortByColumns(Filter(ItemCategoryMaster,And(DirectInd.Value="Indirect",ProdOrServ.Value="Service")),"Title",Ascending)) 
similar code is there for product type box. 
 
But main issue is to clear those comboboxes and let the user select new values. Simple requirement but PowerApps has made it so complex! 

Ok... So, first of all, you can make your Items property a bit less complicated, like this:

 

SortByColumns(Filter(ItemCategoryMaster,And(DirectInd.Value=DataCardValue54.Selected.Value,ProdOrServ.Value="Service")),"Title",Ascending)

 

Then, for resetting your combo boxes when the Direct/Indirect field changes, you could set your ServiceType and ProductType combo boxes DefaultSelectedItems property like this:

If(DataCardValue54.Selected.Value <> ThisItem.DirectInd.Value, Blank(), Parent.Default)

What this formula does is that it sets the combo box to blank if the actual value of the Direct/Indirect field differs from the one in the item that's being edited.

Tell us if this does what you expect...

Anonymous
Not applicable

Hi @R3dKap Appriciate your time for this. 

I checked, this will surely work in one way. If currently saved value is Direct & we chg to Indirect then it show Blank dd. Now we select values in service & product type; and decide to change back to Direct then it will show parent value.  

 

I went back to what I was trying to do until now: 

- OnChange of Direct/Indirect Set(resetvar,true) and this would show {} in the dd below

because we have written DefaultSelectedItems of the 2 dd's as: If(resetvar,{},LookUp(SupplierDetails,ID=lastSubmitID,ServiceType2))  

- OnChange of ServiceType dd Set(resetvar,false) 

But this was giving wiered results when I tried to chg value in Service type dd 

 

Now I've removed OnChange of ServiceType dd & on the OnChange of Direct/Indirect -- Set(resetvar,false);Set(resetvar,true)

This resolve the issue. 

But I also want to be able to save Blank record in SP, If user clicks on review & submit (Patch action) while they are blank. 

Not sure of how to check {} in the combobox. Please suggest.

The only way I know to set a lookup field to a blank value through a Patch is to set its value to:

{Id: -1, Value: Blank()}

So I would suggest that in your Patch operation, you do something like this:

Patch(
    <your datasource>,
    <your record>,
    {
        ...
        <your ServiceType lookup field>: If(IsBlank(DataCardValueServiceType.Selected), {Id: -1, Value: Blank()}, DataCardValueSErviceType.Selected)
        ...
    }
)

Also, one important thing... When you want to set the current (or default) value of a lookup field in a form, consider what's in your combo box Items property as the datasource where you should look for the value to set.

Meaning, if you have a lookup field where the DataCardValueXXX.Items is this...

Choices(<your datasource>.<your lookup field>)

...make sure that you set its current (or default) value doing this in the DefaultSelectedItems property:

LookUp(Choices(<your datasource>.<your lookup field>), Id=<an id>)
-or-
LookUp(Choices(<your datasource>.<your lookup field>), Value=<a value>)

Do not do a lookup to the lookup list as the result will have a different structure than the one provided by the Choices function.

That is a good practice to remember...

Anonymous
Not applicable

Thanks a lot @R3dKap for all your suggestions and answers. Will surely message you in case any help needed in future.  

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (2,537)