pnp / pnpjs

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

searchAllOrganizationUsers not searching the user with 1 or 2 characters it is working with 3 or more characters #3076

Closed bhoomesh-spe closed 6 days ago

bhoomesh-spe commented 2 weeks 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 implemented the below code for the search organization user in the SPFx React project.


import "@pnp/sp/profiles";

const searchUser = async (event) => {
    try {
        let _filteredUser = await searchAllOrganizationUsers(event?.query);
        setTimeout(() => {
            if (_filteredUser?.length > 0) {
                if (!event.query.trim().length) {
                    _filteredUser = _filteredUser;
                }
                else {
                    _filteredUser = _filteredUser.filter((user) => user.Title.toLowerCase().startsWith(event.query.toLowerCase()));
                }
                setFilteredUser(_filteredUser);
            }
        }, 250);
    } catch (ex) {
        console.log("Err", ex);
    }
};

export const searchAllOrganizationUsers = async (queryText) => {
    const sp: SPFI = getSP();
    try {
        const usersResult = await sp.profiles.clientPeoplePickerSearchUser({
            AllowEmailAddresses: true,
            AllowMultipleEntities: true,
            MaximumEntitySuggestions: 25,
            PrincipalType: 1,
            PrincipalSource: 15,
            QueryString: queryText
        });

        if (usersResult.length > 0) {
            const userSuggestions = [];
            for (let i = 0; i < usersResult.length; i++) {
                const userDetails = (await sp.web.ensureUser(usersResult[i].Key)).data;
                if (userDetails) {
                    userDetails["ID"] = userDetails.Id;
                    userDetails["EMail"] = userDetails.Email;
                    userSuggestions.push(userDetails);
                }
            }
            console.log("usersResult", usersResult);
            return userSuggestions;
        }
    } catch (error) {
        throw error;
    }
};

When I try to search user by adding 1 or 2 characters it does not search any user. Please take a look at the screenshots below for more clarification.

Screenshot 2024-06-21 193307

Screenshot 2024-06-21 193337

Can anyone help me with the same?

Thanks

bhoomesh-spe commented 1 week ago

@patrick-rodgers - Can you please help me with the same?

bcameron1231 commented 6 days ago

We're just a proxy to the Microsoft APIs. I have replicated this using the direct SharePoint APIs without PnPjs.

Sorry, but there isn't anything we can do here to fix this.

github-actions[bot] commented 4 days 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.