Tuesday, August 25, 2009

Getting updated item using CAML

Scenario:
Often we need to get items which got changed. Its hard to do it using UI, and also using custom code usually we need to compare values, which can be tedious.

Solution:
CAML supports accessing previous and after property using Old / New keywords.

Someone else changes an event last modified by me:

<Query><And><Eq><Value type="string">spvm\administrator</Value><FieldRef Name="Editor/Old"/></Eq><Neq><Value type="string">spvm\administrator</Value><FieldRef Name="Editor/New"/></Neq></And></Query>
Someone else changes an event created by me:
<Query><And><Or><Eq><Value type="string">spvm\administrator</Value><FieldRef Name="Author/New"/></Eq><Eq><Value type="string">spvm\administrator</Value><FieldRef Name="Author/Old"/></Eq></Or><Neq><Value type="string">spvm\administrator</Value><FieldRef Name="Editor/New"/></Neq></And></Query>
Someone else changes an event:
<Query><Neq><Value type="string">spvm\administrator</Value><FieldRef Name="Editor/New"/></Neq></Query>
The time or location of an event changes:
<Query><Or><Or><Neq><FieldRef Name="EventDate/New"/><FieldRef Name="EventDate/Old"/></Neq><Neq><FieldRef Name="EndDate/New"/><FieldRef Name="EndDate/Old"/></Neq></Or><Neq><FieldRef Name="Location/New"/><FieldRef Name="Location/Old"/></Neq></Or></Query>

0 comments: