我正在尝试编写一个CAML查询,执行以下操作:
获取_ModerationStatus为Approved的所有行
获取_ModerationStatus为Rejected且该行的Requester为当前用户,或者该行的Manager为当前用户的所有行。
获取_ModerationStatus为Pending且该行的Requester为当前用户,或者该行的Manager为当前用户的所有行。
到目前为止,我有这个CAML查询,但是当我运行它时,我得到错误Cannot complete this action. Please try again.
<View>
<Query>
<Where>
<Or>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Approved</Value>
</Eq>
<Or>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Pending</Value>
</Eq>
<Eq>
<FieldRef Name='Requester' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Pending</Value>
</Eq>
<Eq>
<FieldRef Name='Manager' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
</Or>
<Or>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Rejected</Value>
</Eq>
<Eq>
<FieldRef Name='Requester' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Rejected</Value>
</Eq>
<Eq>
<FieldRef Name='Manager' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
</Or>
</Or>
</Where>
</Query>
</View>
我很确定我没有正确应用<Or>
和<And>
操作符,因为像这三个这样简单的查询对我来说是有效的:
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Approved</Value>
</Eq>
</Where>
</Query>
</View>
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Rejected</Value>
</Eq>
</Where>
</Query>
</View>
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Pending</Value>
</Eq>
</Where>
</Query>
</View>
我使用U2U Caml Query Builder最终得到了这个有效的Caml。
<Query>
<Where>
<Or>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Approved</Value>
</Eq>
<Or>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Rejected</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Requester' />
<Value Type='User'>
<UserID />
</Value>
</Eq>
<Eq>
<FieldRef Name='Manager' />
<Value Type='User'>
<UserID />
</Value>
</Eq>
</Or>
</And>
<And>
<Eq>
<FieldRef Name='_ModerationStatus' />
<Value Type='ModStat'>Pending</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Requester' />
<Value Type='User'>
<UserID />
</Value>
</Eq>
<Eq>
<FieldRef Name='Manager' />
<Value Type='User'>
<UserID />
</Value>
</Eq>
</Or>
</And>
</Or>
</Or>
</Where>
<OrderBy>
<FieldRef Name='EventDate' Ascending='True' />
</OrderBy>
</Query>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='Location' />
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<FieldRef Name='Description' />
<FieldRef Name='Requester' />
<FieldRef Name='Manager' />
</ViewFields>
<QueryOptions />