Solved! Go to Solution.
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...
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?
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:
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...
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...
Thanks a lot @R3dKap for all your suggestions and answers. Will surely message you in case any help needed in future.