pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
740 stars 300 forks source link

Some of the SharePoint Online users are not showing in the Auto Complete or People Picker #3046

Closed bhoomesh-spe closed 1 month ago

bhoomesh-spe commented 1 month ago

What version of PnPjs library you are using

3.x

Minor Version Number

3.15.0

Target environment

SharePoint Framework

Additional environment details

SharePoint Online, SPFx React

Question/Request

Hello Everyone,

I have added Everyone except external users to the Team Site Visitors group. Below is the screenshot for the same. Screenshot 2024-05-30 001747

Now I have tried to search for one user in the People Picker but the user does not appear in the search results. Below is the screenshot for the same. Screenshot 2024-05-30 002025

The user I have searched in the auto-complete is the user of our organization. Below is the screenshot for the same. Screenshot 2024-05-30 002147

I have used the below code for getting site users from the SharePoint User Information list.

export const getSharepointUser = async () => {
    const sp: SPFI = getSP();
    return sp.web.siteUserInfoList.items
        .select("*,ID,Title,Name,EMail,JobTitle,SipAddress,WorkPhone,MobilePhone").getAll()
        .then((res) => {
        console.log("res..", res);
            return res;
        })
        .catch((err) => {
            console.log("err..", err);
            throw err;
        });
};

Why did the user not appear in the search? Does anyone have an idea?

Thanks

juliemturner commented 1 month ago

@bhoomesh-spe - Because users are not added to the hidden siteUserInfoList until either a) they access the site or b) you call ensureUser for their user id. If you want to just "search" for a user, you should use the search endpoint instead which at this point is most easily done with SharePoint Search -- you'll want to make sure your search includes the sourceId for People which is the same for every tenant -- but also can be done with Microsoft Graph Search

SharePoint Search example

  const q: SearchQueryInit = SearchQueryBuilder(`${searchString}`)
        .sourceId("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31")
        .rowLimit(500)
        .rowsPerPage(500)
        .selectProperties("SipAddress", "PreferredName", "AccountName", "Department", "JobTitle")
        .trimDuplicates;
  const people: SearchResults = await this._sp.search(q);
bhoomesh-spe commented 1 month ago

@juliemturner - Thanks for the quick response. Can we load all users for the site using the PowerShell script? i.e. The admin can run the script from SharePoint Online Management Shell and all users appear in the search.

patrick-rodgers commented 1 month ago

@bhoomesh-spe - while we try and be helpful, this is not a general support forum. Yes, you can load all the users from a PowerShell script, but that has nothing to do with PnPjs so we're not able to provide that guidance. Will close this issue as answered. Thanks!

juliemturner commented 1 month ago

I'm just going to add, all the users already show in search just not in the site's hidden user list. Search is not the intent of the hidden user list it's a lookup list for any User based list/site columns.

github-actions[bot] commented 1 month ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.