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

The correct way of setting up a Office365.SearchUsers combobox in an EDIT form

Hi,

I am using a Combobox in a datacard to add an internal client to a record within an edit form (I have a separate 'new' form with the combobox and that works fine).
Try as I might, I cannot get it to work. When navigating from the gallery, it obviously needs to be blank if the client field in the record being edited is blank, and if not, pre-select the existing user in the field, then allow me to edit it. All the variations I have tried within the 'DefaultSelectedItems' property, it either pulls in the first entry from our Active Directory if the existing field is blank, or if I try to avoid that, I cannot use the combobox to search a user.
As this is the most common use of a combobox, I'm assuming others are managing to do this. Would anyone please share how it's done?
Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
JamFestival
Resolver I
Resolver I

Thanks to @v-bofeng-msft for the essential advice.

 

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, but only if the variable is false
If(varNoClient2=false,
   Office365Users.SearchUser({searchTerm:ThisItem.CO2_ID}),
   Blank()
)

 

 

 

View solution in original post

1 REPLY 1
JamFestival
Resolver I
Resolver I

Thanks to @v-bofeng-msft for the essential advice.

 

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, but only if the variable is false
If(varNoClient2=false,
   Office365Users.SearchUser({searchTerm:ThisItem.CO2_ID}),
   Blank()
)

 

 

 

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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (5,343)