cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Future_Vision
Responsive Resident
Responsive Resident

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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Future_Vision
Responsive Resident
Responsive Resident

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

View solution in original post

3 REPLIES 3
Wayne_A
Advocate III
Advocate III

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!

Future_Vision
Responsive Resident
Responsive Resident

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. 

Future_Vision
Responsive Resident
Responsive Resident

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

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (21,368)