cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Voltes
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

@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

5 REPLIES 5
mdevaney
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."

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

 

 

@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

Hi @mdevaney ,

 

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

 

Thanks.

ericonline
Community Champion
Community Champion

You are the cat @mdevaney ! Your blog is super good too man! Thank you for all the work you put in to bring out the best in this toolset.

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (38,215)