How do I use list.GetChangesBatchAsync() to Get ALL Changes for a Given Change Query? #1228
-
I am trying to create an extension method that will allow me to get ALL of the changes that occurred for a given change query and I thought I would use public static async Task<IList<IChangeItem>> GetAllChangesAsync(this IList list, ChangeQueryOptions queryOptions)
{
Batch batch = list.PnPContext.NewBatch()!;
IEnumerableBatchResult<IChange>? changes = await list.GetChangesBatchAsync(batch, queryOptions);
// Do something to get ALL changes...
var results = await list.PnPContext.ExecuteAsync(batch);
// How do I get all changes in one list to return?
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@adamfisher : why do you need multiple calls to get all changes. If you use below you'll get all changes returned. Are you looking into paging the changes? The idea is you initially read the list information you need using regular APIs, then get the last change token (you can use the var changes = await list.GetChangesAsync(new ChangeQueryOptions(true, true)); |
Beta Was this translation helpful? Give feedback.
-
I ended up doing this since I couldn't figure out how to use the batch version: public static async Task<List<IChange>> GetAllChangesAsync(this IList list, ChangeQueryOptions queryOptions)
{
IList<IChange> changes = await list.GetChangesAsync(queryOptions);
List<IChange> results = new(changes);
while (changes.Count > 0)
{
var lastChangeToken = changes.Last().ChangeToken;
queryOptions.ChangeTokenStart = lastChangeToken;
changes = await list.GetChangesAsync(queryOptions);
results.AddRange(changes);
}
return results;
} |
Beta Was this translation helpful? Give feedback.
I ended up doing this since I couldn't figure out how to use the batch version: