-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemUpdateAsync causes "Property ListId was not loaded" #570
Comments
@berntrune: You cannot simply update the Modified property, you always need to pass along the 4 properties (Author, Editor, Modified, Created). See #522 (comment) for more context and a working sample. Can you try that and see if it works. The fact that you did not get an error calling Update() means that updating the modified field most likely also did not happen. |
@jansenbe Thanks for the sample. I added the other system properties with no luck. In my scenario I'm creating a new file and saving system properties, not opening an existing item and saving system properties. Can that be the issue? Do you have a test for this scenario? |
Hi @berntrune, Can you try below sample, this works for me in my lab for changing the created/modified/title properties of a document var doc = await context.Web.Lists.GetByTitleAsync("Documents", p => p.Fields);
// Use below approach to also update the Author/Editor fields
//var doc = await context.Web.Lists.GetByTitleAsync("Documents", p => p.Fields);
var file = await doc.RootFolder.Files.AddAsync("ClassifyAndExtractFile.docx", System.IO.File.OpenRead($".{System.IO.Path.DirectorySeparatorChar}TestAssets{System.IO.Path.DirectorySeparatorChar}test.docx"), true);
// Load the file again to get the ListItemFields populated
file = await context.Web.GetFileByServerRelativeUrlAsync(file.ServerRelativeUrl, p => p.ListItemAllFields);
// Load the current user (e.g. when setting editor and author)
// var currentUser = await context.Web.GetCurrentUserAsync();
var newDate = new DateTime(2020, 10, 20);
// Load the Author and Editor fields
//var author = doc.Fields.AsRequested().FirstOrDefault(p => p.InternalName == "Author");
//var editor = doc.Fields.AsRequested().FirstOrDefault(p => p.InternalName == "Editor");
file.ListItemAllFields["Title"] = "new title";
file.ListItemAllFields["Created"] = newDate;
file.ListItemAllFields["Modified"] = newDate;
// Optionally also set the author and editor
//file.ListItemAllFields["Author"] = author.NewFieldUserValue(currentUser);
//file.ListItemAllFields["Editor"] = editor.NewFieldUserValue(currentUser);
await file.ListItemAllFields.UpdateOverwriteVersionAsync(); |
@berntrune : doing some more digging I found a related bug. After adding a file one needs to load the ListItemAllFields property and that failed using |
… properties on an added file. See #570
@berntrune : are you good with closing this one? |
@jansenbe : Not tested complete yet, can we keep it open a couple of days more? |
@berntrune : any update? |
@berntrune : closing this one, feel free to re-open if the issue is not solved |
Discussed in #569
Originally posted by berntrune October 11, 2021
I am trying to update Modifed field using PNP SystemUpdateAsync.
When using UpdateAsync, all normal item fields are stored successfully (except Modified of course).
When changing to SystemUpdateAsync I get "Property ListId was not yet loaded". (see stack trace below)
using (var ctx = await _pnpContextFactory.CreateAsync(new Uri("http://site")))
{
var doc = await ctx.Web.Lists.GetByTitleAsync("Documents");
var file = await doc.RootFolder.Files.AddAsync("file.docx", fileStream, true);
file.ListItemAllFields["Title"] = "new title";
file.ListItemAllFields["Modified"] = DateTime.Now;
//await file.ListItemAllFields.UpdateAsync();
await file.ListItemAllFields.SystemUpdateAsync();
}
at PnP.Core.Model.TransientObject.GetValue[T](String propertyName)
at PnP.Core.Model.SharePoint.File.get_ListId()
at PnP.Core.Model.SharePoint.ListItem.d__80.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PnP.Core.Model.SharePoint.ListItem.d__83.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at LargeFileTransfer.TransferFile.d__3.MoveNext() in C:\DevopsGit\Bikube.Azure.Services.BergenFunction\TransferFile.cs:line 109
Normally, in csom, I've been able to swap these methods without any issues.
Any clues?
The text was updated successfully, but these errors were encountered: