cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

How to set default value for combo box with user name

Hi guys,

 

How to give default value to a ComboBox with current user name ?

I tried to put in property Default or DefaultSelectedItem but returned error. I'm using User().Fullname

 

In Items property I already have this : Office365Users.SearchUser({searchTerm:MyComboBoxName.SearchText}), this is so that when we type in my combo box, it is automatically filter the list. But I need to be filled in by current user name at first.

 

I found this thread : https://powerusers.microsoft.com/t5/Building-Power-Apps/Default-value-of-combo-box/m-p/298441#M85966

but to me it is hard to understand why ?

 

Thanks,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

@Voltes 
Yes of course.  This is the most important section of my code.

{ 
    DisplayName:User().FullName,
    Claims:"i:0#.f|membership|" & Lower(User().Email), 
    Department:"", 
    Email:User().Email, 
    JobTitle:"", 
    Picture:""
}

 
A person field in SharePoint is known as a complex column type.  This means it stores more than one piece of data about a person.  In fact it stores several! 

  • DisplayName: Office 365 display name
  • Claims: a unique identifier that represents a specific user
  • Email: the user's email etc.
  • Picture: Office 365 user photo
  • etc, etc, etc.


So when we want to display a person in a new Power Apps form we must build the person object from scratch.  That's why we need all of that code inside the { } brackets. 

 

I would suggest you copy my code entirely.  At the very least you must have these fields: Claims, DisplayName, Email.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

4 REPLIES 4
Highlighted
Super User III
Super User III

@Voltes 

You should be able to just copy and paste this code into the DefaultSelectedItems property of your ComboBox and have it work.

 

If(Form1.Mode=FormMode.New,
    { 
      DisplayName:User().FullName,
      Claims:"i:0#.f|membership|" & Lower(User().Email), 
      Department:"", 
      Email:User().Email, 
      JobTitle:"", 
      Picture:""
    },
    ThisItem.YOURFIELDNAME
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted

Hi @mdevaney 

 

Yes, it works. Much appreciated if you can tell me just a little, what is the meaning of that code ?

I've put the 1st line only actually, since I thought I only need the name in that box. Will that make the code invalid or missed its purpose ? 

 

So, it is like this:

Voltes_0-1603284713006.png

Thanks again.

V

 

 

Highlighted

@Voltes 
Yes of course.  This is the most important section of my code.

{ 
    DisplayName:User().FullName,
    Claims:"i:0#.f|membership|" & Lower(User().Email), 
    Department:"", 
    Email:User().Email, 
    JobTitle:"", 
    Picture:""
}

 
A person field in SharePoint is known as a complex column type.  This means it stores more than one piece of data about a person.  In fact it stores several! 

  • DisplayName: Office 365 display name
  • Claims: a unique identifier that represents a specific user
  • Email: the user's email etc.
  • Picture: Office 365 user photo
  • etc, etc, etc.


So when we want to display a person in a new Power Apps form we must build the person object from scratch.  That's why we need all of that code inside the { } brackets. 

 

I would suggest you copy my code entirely.  At the very least you must have these fields: Claims, DisplayName, Email.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Highlighted

Hi @mdevaney ,

 

Many thanks for the explanation. It really help me to understand more on this.

 

Thanks.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

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