สร้าง People Picker ใน Power Apps ด้วย Office 365 Users connector

by

ใน Power Apps สามารถสร้าง People Picker โดยใช้ Office 365 Users Connector ได้

อ่านรายละเอียดเพิ่มเติมเกี่ยวกับ Office 365 User connector ที่นี่

ไปที่ tab “Data” กดปุ่ม “Add Data” แล้วค้นหา connector “Office 365 Users”

เมื่อเรา Add data Office 365 Users connector แล้ว ให้ Insert control “Combo box”

ที่ Properties ของ Combo box (Dropdown ทางด้านซ้ายบนของหน้าจอ) ให้เลือก “Items” Properties

เราจะเขียนสูตร Office365Users.SearchUserV2 ซึ่งมี syntax ดังนี้

Office365Users.SearchUserV2({searchTerm:Text, top:Number, isSearchTermRequired:Boolean, skipToken:Text})

อ่านรายละเอียด parameter ต่างๆ ของ SearchUserV2 ที่นี่

ในที่นี้เราจะไม่ได้เขียนสูตรโดยใช้ ทุก parameter และมีการใช้สูตร Trim ใน parameter searchTerm

Office365Users.SearchUserV2({searchTerm:Trim(Self.SearchText), isSearchTermRequired:false})

ตั้งค่า Allow multiple Selection, Allow Searching

Properties tab : Toggle on for “Allow multiple selection” and “Allow Searching”

กด Edit Fields แล้วตั้งค่าตามรูป

Edit Fields

ถ้าต้องการให้ Search ได้หลายอย่าง เช่น ค้นหาด้วย DisplayName ค้นหาด้วย mail ให้ปรับค่าที่ Advanced > SearchFields ตามด้านล่าง

ที่ Combo box จะมี Properties ชื่อ InputTextPlaceholder อยู่ เราสามารถแก้ไขข้อความนี้ได้ ค่าตั้งต้นจะเป็นคำว่า “Find items”

Combobox InputTextPlaceholder (Default)

ให้ไปที่ Advanced tab หา InputTextPlaceHolder

Go to Advance tab and find InputTextPlaceholder
Revise
Combobox InputTextPlaceholder (Revised)

กด Preview แล้วลองค้นหา Users

ภาพนี้ยังไม่ได้ filter External Users ออกไป

ถ้าต้องการ Filter ให้มีแค่ account ที่ Active และมีแค่ Internal Users ให้เขียนสูตร

Filter(Office365Users.SearchUserV2(
    {
        searchTerm: Trim(Self.SearchText),
        isSearchTermRequired: false
    }
).value,
AccountEnabled = true && Not("#EXT" in UserPrincipalName))

กด Preview แล้วลองค้นหา Users

ภาพนี้ filter External Users ออกไปแล้ว

Did You Enjoy this Article?

Subscription to get new articles sent to your inbox each week for FREE

Question?

If you have any questions or feedback about this article please leave a message in the comments section below.

Subscribe to get new articles sent to your inbox each week for FREE