admin管理员组文章数量:1203816
I am using the following function to fetch all users from SharePoint:
const fetchUsers = (): void => {
setLoading(true);
const listUrl = `${Context.pageContext.web.absoluteUrl}/_api/web/siteusers`;
console.log('List URL is', listUrl);
console.log('Context.pageContext.web:', Context.pageContext.web);
Context.spHttpClient.get(listUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => response.json())
.then((data) => {
console.log('Fetched users:', data.value);
const users: User[] = data.value.map((user: SPUser) => ({
id: user.Id,
name: user.Title,
email: user.Email,
}));
setAllUsers(users); // Store all users once fetched
setOptions(users); // Populate options initially
setLoading(false);
})
.catch((error) => {
setLoading(false);
console.error('Error fetching users:', error);
});
};
Although I am successfully fetching all users, I am encountering an issue when submitting the data to a SharePoint list. Specifically, the Attendees column in the list remains empty after submission.
Here’s the payload I am sending:
const payload = {
Title: formData.title,
Description: formData.description,
StartDate: formattedStartDate, // SharePoint date-time format
EndDate: formattedEndDate, // SharePoint date-time format
Category: formData.category === "" ? "Other" : formData.category,
Allday: isDateOnly, // All-day event flag
// AttendeesId: [9,15] // These are the correct IDs when manually inserted, and the data appears in the list.
AttendeesId: attendees.map(attendee => attendee.id) // IDs fetched using /siteusers endpoint.
};
The problem is that the IDs fetched from the /siteusers endpoint (e.g., [422, 203]) do not match the correct IDs expected by the SharePoint User or Group column (e.g., [9, 15]).
Although I know I can use Microsoft Graph API to fetch user data, I want to know:
- Is it possible to get the correct user IDs using SharePoint REST API?
- If yes, can you provide the correct endpoint for this?
Any guidance would be greatly appreciated!
I have already tried using the API endpoint: /_api/web/siteusers
While this fetches user data successfully, the issue is that the IDs returned by this endpoint do not match the IDs required by the SharePoint** User or Group** column.
I want to know:
Is there any approach to get the correct IDs that match the SharePoint User or Group column? Any help or guidance would be greatly appreciated!
本文标签: How to Retrieve All Users with Correct User IDs in SharePoint SPFxStack Overflow
版权声明:本文标题:How to Retrieve All Users with Correct User IDs in SharePoint SPFx? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738613542a2102772.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论