cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
moritz0815
Frequent Visitor

Clear ComboBox and save empty value

Hello dear community,

I have several ComboBoxes in my form that affect each other.
ComboBox1 has the choices "Yes" and "No".
When ComboBox1 is set from "Yes" to "No", all other ComboBoxes should be reset to blank.
When the form is submitted now, blank/null should also be entered in the SharePoint list. If there was an entry, it should be overwritten with blank/null.

My previous approach was that on the Combobox1 OnChange, a variable (DoReset) is set to true when the change from "Yes" to "No" is completed.

The DefaultSelectedItems formula is then adjusted like this: 

If(OnReset;myType;Parent.Default)

myType is defined like this: 

Set(myType; {Value: Blank()});;

How do I now manage to overwrite existing values with blank/null on submit?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @moritz0815 ,

That is really strange (also Id is normally associated with a Lookup column) as I have never had any difficulties clearing Choice columns when I use them. However I recall back in the rather deep past seeing that code being used, but a Choice field does not have an Id. I also answered this post a few months back with the same issue and it worked there. However if it works for you, it can be improved a bit to

If(
   OnReset;
   {
       Id: -1;
       Value: Blank()
   };
   {Value: DataCardValue20.Selected.Value}
}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

View solution in original post

11 REPLIES 11
WarrenBelz
Super User
Super User

Hi @moritz0815 ,

You are almost there - two further things - the Reset of these should be

OnReset

OnChange of the Combo Box

UpdateContext({OnReset: false});
UpdateContext({OnReset: true})

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

moritz0815
Frequent Visitor

Thank you for the extremely helpful reply.
I was able to create exactly the behavior I was looking for.

However, when saving the data (submit) to the SharePoint list, the empty entry is saved only for the text columns. For the Choice columns, the existing entry is not overwritten with "empty".

I would like to avoid allowing " " as a choice, if that is possible.

Note: "Formula-level error management" is enabled in the settings.

Hi @moritz0815 ,

What is the Items of the Combo Box, the Update of the Data Card and the name and type of field it is writing to ?

moritz0815
Frequent Visitor

@WarrenBelz 
The Items of the ComboBox is: 

Choices([@'Wahlpflichtfach Datensatz'].Prio1)

The Update of the Data Card is: 

DataCardValue15.Selected

And the name and type of the field is: 

I think the name ist the column-name: Prio1

Type: Choices

 

Hi @moritz0815 ,

That should actually work, but try on the Update

{Value: DataCardValue15.Selected.Value}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

moritz0815
Frequent Visitor

Hi @WarrenBelz,

unfortunately, the change has not brought any noticeable effect. The reseted values are not overwritten with "empty", they remain even though the ComboBox has no SelectedItems.

Hi @moritz0815 ,

Updated suggestions below

Items of Combo Box

Choices([@'Wahlpflichtfach Datensatz'].Prio1)

DefaultSelectedItems 

{
   Value: 
   If(
      DoReset,
      Blank(),
      ThisItem.Prio1.Value
   )
}

Update of the Data Card (maybe overkill, but try this)

{
   Value:
   If(
      DoReset,
      Blank(), 
      DataCardValue15.Selected.Value
   }
)

ComboBox1 OnChange

If(
   Self.Selected.Value = "No",
   UpdateContext({DoReset: false});
   UpdateContext({DoReset: true})
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

moritz0815
Frequent Visitor

Unfortunately, it just won't work, even with the latest update.

Maybe I have to allow "" as a selection in the share point list after all and simply not offer this choice to the user in the ComboBox?

Update: 

I have actually taken a step forward.
I have modified update of the Data Card like this:

 

{
    Id:If(
        OnReset;
        -1
    );
    Value: If(
        OnReset;
        Blank();
        DataCardValue20.Selected.Value
    )
}

 

As now I can perform the reset and in the Choices Column is actually stored the empty value. Unfortunately, saving non-empty values does not work now. My guess, it is because of the missing ID when OnReset returns false. What would I have to use here?

 

{
    Id:If(
        OnReset;
        -1;
        'Right_ID?'
    );
    Value: If(
        OnReset;
        Blank();
        DataCardValue20.Selected.Value
    )
}

 

Update 2: It works if I do the following:

Great that it works now. I just don't understand why it works, unfortunately. Maybe someone can give me some clarity here.

{
    Id: If(
        OnReset;
        -1;0
    );
    Value: If(
        OnReset;
        Blank();
        DataCardValue20.Selected.Value
    )
}

 

@moritz0815 ,

Is that a Lookup or a Choice column ? This is the first time Id has been mentioned.

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.

Users online (3,303)