I have the following code which tries to get change logs from a list using client object model. It returns no changes in changecollection on some environments but works fine on other envs. See the line in code highlighted.
I also checked the "changelogexpirationperiod" which is well set to 60 days. I even disabled the changelog expiration but no success.
Does anyone know whats going on??
ClientContext context = new ClientContext("someurlhere");
ChangeQuery changeQuery = new ChangeQuery(false, true
web = context.Web;
List list = context.Web.Lists.GetByTitle("DemoList"
changes = list.GetChanges(changeQuery);
foreach (Change change in
SPList.getChanges() and SPSite.getChanges() is related with the Change Log timer job, it may returns no changes after running Change Log timer job. Here is a similar thread that is solved by modify the value of @IgnoreChangeNumberIfNotFound in the query when calling getChanges(), you can refer to it for more information:
The value of the @IgnoreChangeNumberIfNotFound variable can be change by altering the stored procedure on the server.
Is there any other solution to this apart from doing that? (Modifying that Sproc is a bad idea IMO - who knows what bad things will happen as a result of doing that)
Instead of changing the stored procedure, I found a different approach which seems to be working just fine. As the "Change Log timer job" seems to cause the trouble I looked up what it's doing and the purpose is to delete events older than 60 days. So when calling GetChanges on anything like SPWeb, SPList .. it doesn't make sense to try to get changes older than 60 days. So instead of calling GetChanges without any parameter you start create a changetoken and receive all changes from the last 60 days.
DateTime startTime = DateTime.UtcNow.AddDays(-60); SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.Web,webSite.ID, startTime); SPChangeCollection changes = webSite.GetChanges(startToken);
I found the code on this Microsoft Website. So with this code no changes to the stored procedure are required. Although I still think it's some kind of a bug!
- Proposed as answer by Andreas Blueher Friday, November 30, 2012 7:40 AM