cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JamFestival
Resolver I
Resolver I

Combobox with Office365Users SearchUser in an Edit Form - prevent defaulting to first user when the datasource field is empty

I have created an internal ticketing system for content development.

 

I have separate dedicated 'New' and 'Edit' screens with forms, so I'm not using mode switching, The 'Edit' screen is navigated to from a Gallery selection.

My datasource is a SharePoint list. In the list, there are two columns for client1 and an optional client2 where there are two stakeholders.

In both the separate 'Edit' and 'New' screen's forms, there are 2 DataCards for specifying the client and an optional second client, In both, have two inputs - a text input and a combobox (with the combobox as the output).
In both, for the Combobox in 'Items' I have :
Office365Users.SearchUser({searchTerm:DataCardTextInput.Text})

In in 'Edit' screen, I have also populated the DefaultSelectedItems (I suspect this is where I'm going wrong...), I have:
Office365Users.SearchUser({searchTerm:Gallery1.Selected.'Client 2'})

 

It works just fine for pulling in the existing record and editing, but only if the fields are populated. The issue I am having is that on visible, where the optional second client datacard hasn't been selected in the 'New' form, instead of being blank, it displays the first person on our company's Office365Users list, which is then patched into the record when you submit the form, even if you remove it from the combobox.

 

I would really appreciate any guidance.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @JamFestival ,

 

The point is that even if you did not select any item in a gallery, the galley will select the first item by default.

 

If you do not want the combo box show anyone while the user has not select any item in gallery , you could try:

1\Set the app's OnStart property to

 

Set(IsSelect,false)

 

and then run OnStart

vbofengmsft_0-1653295077479.jpeg

 

2\Set the gallery's  OnSelect property to:

 

Set(IsSelect,true)

 

3\Set the combo box's defaultselecteditems to

 

If(
   IsSelect,
   Office365Users.SearchUser({searchTerm:ThisItem.'Client 2'}),
   Blank()
)

 

In addition, if you want make the form into New mode or Display mode, you need to set the IsSelect to false.

 

Best Regards,

Bof

View solution in original post

4 REPLIES 4
JamFestival
Resolver I
Resolver I

Update

I thought I had a breakthrough, but no.
I have tried setting a context variable as 'false' OnVisible on the screen if the Gallery.Selected field is blank, else 'true'. I then updated the defaultselecteditems:

If(ContextVariable = true,Office365Users.SearchUser({searchTerm:ThisItem.'Client 2'}))

Unfortunately, although this succeeds in preventing it from automatically showing the first Office365 person, it now no longer lists the users when anything is typed into the text input. I think, if this were to work, I'd need an 'else', but I don't think it's possible to set DefaultSelectedItems in a Combobox to 'null'.

Hi @JamFestival ,

 

The point is that even if you did not select any item in a gallery, the galley will select the first item by default.

 

If you do not want the combo box show anyone while the user has not select any item in gallery , you could try:

1\Set the app's OnStart property to

 

Set(IsSelect,false)

 

and then run OnStart

vbofengmsft_0-1653295077479.jpeg

 

2\Set the gallery's  OnSelect property to:

 

Set(IsSelect,true)

 

3\Set the combo box's defaultselecteditems to

 

If(
   IsSelect,
   Office365Users.SearchUser({searchTerm:ThisItem.'Client 2'}),
   Blank()
)

 

In addition, if you want make the form into New mode or Display mode, you need to set the IsSelect to false.

 

Best Regards,

Bof

JamFestival
Resolver I
Resolver I

I would have selected a record, but the record may have an empty 'client' field.
The principle of your suggestion might still work if I set a variable if the selected record has that field blank. Something like: 

If (IsBlank(Gallery1.Selected.Client)=false,Set(varNoClient,true))

 I'll give that a try now.

Hi @v-bofeng-msft 
Thank you SO much for your guidance!
With your advice, I was able to make it perform as desired.
The key factor that I was missing was ensuring that the form 'knew' that the field was empty prior to navigating to the edit screen. 
Here's what worked:
1. On the gallery's screen, I added this to the 'OnVisible' property:

Set(
    varNoClient2,
    false
)

2. On the edit icon in the gallery, my 'On Select' property:

 

//Select the record, and set the variable to true if the ID field is blank, then navigate to the edit screen
Select(Parent);
If(IsBlank(Gallery1.Selected.CO2_ID)=true,Set(varNoClient2,true));
Navigate('Edit Record',ScreenTransition.Cover)

 

3. In the edit screen, in the edit form, in the combobox, I set the 'DefaultSelectedItems' to:

 

//Use the ID field to populate
If(varNoClient2=false,
   Office365Users.SearchUser({searchTerm:ThisItem.CO2_ID}),
   Blank()
)

 

 

Wonderful!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,269)