Created
May 21, 2021 14:24
-
-
Save manuelsidler/7750ff2bdab9a03d8da00e04aa877f00 to your computer and use it in GitHub Desktop.
Create list item with people lookup field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var expenseItem = new ListItem | |
{ | |
Fields = new FieldValueSet | |
{ | |
AdditionalData = new Dictionary<string, object> | |
{ | |
{"Title", expense.Title}, | |
{"Zeitpunkt", expense.Date}, | |
{"Betrag", expense.Amount}, | |
{"MitarbeiterLookupId", await GetUserLookupId(expense.User)} | |
} | |
} | |
}; | |
var createdItem = await _graph | |
.Sites[_configuration["SiteId"]] | |
.Lists["Spesen"] | |
.Items.Request().AddAsync(expenseItem, cancellationToken); | |
private async Task<string> GetUserLookupId(string user) | |
{ | |
var hiddenUserListId = (await _graph | |
.Sites[_configuration["SiteId"]] | |
.Lists.Request().Filter("displayName eq 'Benutzerinformationsliste'") | |
.GetAsync())[0].Id; | |
var userLookupId = (await _graph | |
.Sites[_configuration["SiteId"]] | |
.Lists[hiddenUserListId] | |
.Items | |
.Request() | |
.Header("Prefer", "HonorNonIndexedQueriesWarningMayFailRandomly") | |
.Filter($"fields/UserName eq '{user}'") | |
.GetAsync())[0].Id; | |
return userLookupId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment