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

ComboBox prepopulate user() and patch

I have read a new of posts and I'm struggling with something...
Like many other suggestions I'm declaring a varUser on app start to = User()
I have a combo box labeled "CmbRequestor"

selectMultiple: false

isSearchable: true

items: Office365Users.SearchUser({searchTerm: CmbRequestor.SearchText})
defaultSelectedItems: {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: Concatenate(
"i:0#.f|membership|",
Lower(varUser.Email)
),
Department: "",
DisplayName: varUser.FullName,
Email: varUser.Email,
JobTitle: "",
Picture: ""
}

The form will display the users display name in the combobox. Brilliant....
I give them the capability to change it if they want and if they do change it - it will work.

BUT if they submit it without changing it (showing the default value) it fails and here's why....the Requestor in the patch statement is expecting my values to all be stored in the comboBox variable...that variable as mentioned above is called CmbRequestor.

Patch(
    'Ticket Request',
    Defaults('Ticket Request'),
    {Title: "Request"},
    {
        Requestor: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: Concatenate("i:0#.f|membership|",Lower(CmbRequestor.Selected.Mail)),
            Department: "",
            DisplayName: CmbRequestor.Selected.DisplayName,
            Email: CmbRequestor.Selected.Mail,
            JobTitle: "",
            Picture: ""
        }
    } etc... 

But it doesn't recognize the CmbRequestor to have a mail value... ONLY a displayname. So what's happening is because I don't search it absolutely requires my defaultSelectedItems to be correct...why is it not recognizing the email address??? Below you can see the DisplayName populated... but the Email is not showing up???

Not the value of the ExecutiveVP below is what it should look like for claims and email. So I think I know what I'm doing but something is not registering for me here why that default isn't sufficient to be stored under the defaultSelectedItems.


sasrsc1966_0-1636757451232.png

 

As  a bonus for those smart people: why is it that I have to populate the default value in the defaultSelectedItems  and not simply Default? Multiple is set to false.

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @sasrsc1966 ,

I must admit I stay away from people fields (just get it with the O365Users connector and store it in Text), but the below may work on your Items (you did not say how you formed the Variable.

With(
   {
      wUser:
      If(
         IsBlank(CmbRequestor.SearchText),
         varUser().Email,
         CmbRequestor.SearchText
      )
   },
   Office365Users.SearchUser(
      {searchTerm: wUser}
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

View solution in original post

2 REPLIES 2
WarrenBelz
Super User
Super User

Hi @sasrsc1966 ,

I must admit I stay away from people fields (just get it with the O365Users connector and store it in Text), but the below may work on your Items (you did not say how you formed the Variable.

With(
   {
      wUser:
      If(
         IsBlank(CmbRequestor.SearchText),
         varUser().Email,
         CmbRequestor.SearchText
      )
   },
   Office365Users.SearchUser(
      {searchTerm: wUser}
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

In the end I took your advice and did this.
In my case I do need to keep the column a special "person" column in SP.

So for the defaultSelectedItems I did...

 

thisUser

 

For them items I did...(where the combo box is named CmbRequestor)

 

Office365Users.SearchUser({searchTerm: CmbRequestor.SearchText})

 

 Then the key was as you say... I set a variable to thisUser creating the person complex field. This could have been done in numerous places. I happen to do it on a gallery at the onSelect action which then populates the form.

 

Set(thisUser,{
    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
      Claims: Concatenate(
        "i:0#.f|membership|",
        Lower(varUser.Email)
    ),
    Department: "",
    DisplayName: varUser.FullName,  
    Email: varUser.Email,
    JobTitle: "",
    Picture: ""
})

 

For the actual "insert statement"....I took your advice and did...

/* insert into list */
With(
    {
        wUser: If(
            IsBlank(CmbRequestor.Selected.Mail),
            varUser.Email,
            CmbRequestor.Selected.Mail
        )
    },
    If(
        IsEmpty(
            Errors(
                'Ticket Request',
                Patch(
                    'Ticket Request',
                    Defaults('Ticket Request'),
                    {Title: "Request"},
                    {
                        Requestor: {
                            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                            Claims: Concatenate(
                                "i:0#.f|membership|",
                                Lower(wUser)
                            ),
                            Department: "",
                            DisplayName: CmbRequestor.Selected.DisplayName,
                            Email: wUser,
                            JobTitle: "",
                            Picture: ""
                        }
                    },
                    {'Seats Requested': Value(InpHowManyTickets.Text)},
                    {'Parking Pass Requested': Value(InpHowManyPP.Text)},
                    {'Customer Request': DrpIsCustomer.Selected.store},
                    {Comments: InpRequestComments.Text},
                    {EventId: requestEventID},
                    {TicketStatusId: 1}/* = pending */
                )
            )
        ),
    /* display message */
        Notify(
            "Your tickets have been requested.",
            NotificationType.Success
        ),
 /* if unsuccessful notify */
        Notify(
            "There is an error with your request!",
            NotificationType.Error
        )
    )
);



 Thank you as always.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,585)