web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Clearing text input an...
Power Apps
Unanswered

Clearing text input and combo with linked values on button press

(0) ShareShare
ReportReport
Posted on by 12

I have two fields:

Account code = text input
Account = combo box, linked to database table.

I have the following settings:
Account code
Default: 

 

 

_accountCodeUpdate

 

 

OnChange: 

 

 

UpdateContext({_accountCode: accountCode.Text})

 

 

Account:

DefaultSelectedItems:

 

 

Filter('[dbo].[accounts]', id = _accountCode)

 

 

OnChange:

 

 

UpdateContext({_accountCodeUpdate: accountSelect.Selected.id})

 

 

The purpose if the 2 fields here is that I want the Account Code to be where the user scans using a scanner a code, it will then update the combo box Account to the value as per the scanned code.  The combo box acts as a backup, where code is not available to scan the user can look it up by search fields and it will update the Account Code text input once an account is selected.

 

Ideally, the scan code would go directly into the combo box but in testing it won't automatically select the item on scan and needs a second interaction to select the item from the filtered option.

 

What I would like to do is create a button that will clear both the Account Code text input and the Account combo box.

 

As they are both set with defaults looking at variables, I tried setting the button's OnSelect property as follows:

 

 

 

UpdateContext({_accountCode: "",_accountCodeUpdate: ""})

 

 

 

This resulted in red x's and did not work, it also broke the updating of the Account Code text input updating when an option is selected in the Combo Box manually.

 

Can anyone advise on how to maintain my looped connection between Account Code and Account, while also allowing me to reset these fields to blank?

Categories:
I have the same question (0)
  • Verified answer
    Cal13 Profile Picture
    12 on at

    Managed to solve this issue, here is what I did.

     

    Created a new variable _accountRefresh, which is set to 0 when an item is selected via the combo box or when an account code is scanned into the account code field.

     

    I set the button to change the value of _accountRefresh to 1 when it is clicked and I had an IF statement on the default value of the account code text input to be "" if 1, or _accountUpdate if 0.  I also added a reset to the combo box - This turned out to be crucial.

    What I found was that using an IF statement on the combo box DefaultSelectedItems to check the _accountRefresh variable would break the relationship between the combo box and the text input.  I could not get an IF statement to work in this option.  Without an IF statement and without the refresh option on the button, the combo box would not clear on button press when it had an item manually selected in the combo box.  It would; however, clear if the item had been selected due to the input into the text input field.

    The reset appears to be forcing the combo box to re-check the value in the text input, which it wasn't automatically doing when it was changed by button press previously, and therefore it updates to select nothing as there are no values matching "".

    Hope that makes sense to anyone reading this faced with a similar problem.

  • alrezac Profile Picture
    on at

    Hi,

     

    Thanks for your follow up on this and giving such a detailed answer on the issue here. I just wanted to follow up with a little more information on this if you would like to learn more. Feel free to take a look.

     

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-if

     

    Regards,

     

    Alex

     

    -------

     

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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard