Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

How do I combine two conditions for the DefaultSelectedItems property of a combobox?

(0) ShareShare
ReportReport
Posted on by 634

Future_Vision_1-1620151134710.png

 

I'll try and explain this the best that I can. These 3 fields all work together. The Third Party field is hidden unless you choose a value that contains "3rd" in it.

If("3rd" in Source_CB.Selected.crfeb_source,true,false)

The Add Third Party field(group) is hidden if the add3rdPtyGRP variable is false. The Add Third Party button OnSelect sets this variable to true which reveals the group. It also sets add3rdPtyBTN to false which sets its Visible property to false

 

When you type a value into the Add Third Party field and click Add a variable called newThird is set to the value of the Add Third Party field. This value is then patched to the datasource of the Third Party field and the field is refreshed like this
Note: add3rdPtyGRP and add3rdPtyBTN are also changed although this is not important

 

If(
 !IsBlank(AddThirdParty_TB.Value),
 UpdateContext(
 {
 newThird: Patch(
 'Third Parties',
 {'Third Party (crfeb_thirdparty)': AddThirdParty_TB.Value}
 )
 }
 );
 Reset(AddThirdParty_TB)
);
Set(
 add3rdPtyGRP,
 false
);
Set(
 add3rdPtyBTN,
 true
)

 

All fine and dandy. The DefaultSelectedItems property for Third Party is set to newThird if a value exists otherwise it defaults to the parent like this.

 

If(IsBlank(newThird),{crfeb_thirdparty:Parent.Default},newThird)

 

Again, all is great, however if I am editing or making a copy of the original record and change the value in the Source field to a value that does not contain "3rd" in the value the default value of the parent still exists behind the scenes in a global variable called glbFormData. What I basically need to be able to do, in the case of an edit/copy where the Source changes to a value that does not contain "3rd"  is make that Third Party field blank in glbFormData so that when I submit it that value is no longer available. I'm not sure exactly how to do this though. I need to be able to account for the existence of a value in the newThird variable and use that value in the Third Party field when the conditions match otherwise I need to use the value in glbFormData for Third Party unless the Source  field does not contain "3rd" in the value in which case I then need to set the glbFormData.'Third Party'  to blank.

 

Hopefully that is clear. It's barely clear to me and my non-programmer mind. Lol!

 

Categories:
  • Verified answer
    Future_Vision Profile Picture
    Future_Vision 634 on at
    Re: How do I combine two conditions for the DefaultSelectedItems property of a combobox?

    Turn out the simplest way I could find to solve this was set that Third Party field to disabled if "3rd" was in the selected value of the Source field like this:

     

    If("3rd" in Source_CB.Selected.crfeb_source,DisplayMode.Edit,DisplayMode.Disabled)

     

     

    Appears to have solved the problem

  • Future_Vision Profile Picture
    Future_Vision 634 on at
    Re: How do I combine two conditions for the DefaultSelectedItems property of a combobox?

    Hmm. I've been playing with that but I don't think that works. I think I may need nested if statements. In one case the field should be set to the variable newThird and in another case it should be set to Blank(). I think a potential solution is to remove the value from the record when the field is inactivated if that makes sense. 

     

    If the user ads a new third party then the field is set to the value of the newThird variable. If the user sets the source to a value that does not include "3rd" then the glbFormData.thirdparty is set to blank. 

  • Wayne_A Profile Picture
    Wayne_A 113 on at
    Re: How do I combine two conditions for the DefaultSelectedItems property of a combobox?

    Are you not able to just use an And() function within your If()?
    e.g.
    If(And(IsBlank(newThird),SomeOtherScenarioHere),{crfeb_thirdparty:Parent.Default},newThird)
    or would an Or() function work better for your scenario and maybe not an And()?


    Like it? please click the Thumbs Up button!
    Problem Solved? please click the Accept as Solution button to help other Community members find the answer as well!

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard