使用Elements.xml部署Web部件实例时如何在CQWP中使用QueryOverride?
-
09-12-2019 - |
题
我需要使用超过三个过滤器的CQWP,因此我将使用像 。使用Elements.xml i.e.AllUsersWebPart和CDATA部署Web部件实例,我无法在部署Web部件实例时获得此操作。
我用普通过滤器的方式就像以下(来自Elements.xml)
<AllUsersWebPart ID="FindingsCQWP" WebPartZoneID="Middle" WebPartOrder="1" >
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="GroupBy" type="string" />
<property name="FilterValue2" type="string">Draft</property>
... and so forth...
.
然而 queryoverride使用cdata 。问题是我不允许“思考”嵌套的CData元素。我尝试过 html编码 caml作为解决方法/方法,但无济于事。
这里的解决方案是什么?我想我可以编写一些功能接收器代码,但我想避免我可以。
解决方案 2
@Andrey's response pinpointed me to the answer of this question. The Query needs to be Encoded. I tried that in my initial approach, but I must have missed something.
I had this CAML that I wanted to have in my QueryOverride
<Where>
<And>
<And>
<Or>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>Not Started</Value>
</Eq>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>Not Closed</Value>
</Eq>
</Or>
<Leq>
<FieldRef Name='TargetImplDate' />
<Value Type='DateTime'>
<Today />
</Value>
</Leq>
</And>
<Eq>
<FieldRef Name='Category' />
<Value Type='Choice'></Value>
</Eq>
</And>
</Where>
<OrderBy>
<FieldRef Name='ProcessChoice' />
<FieldRef Name='TargetImplDate' />
</OrderBy>
Using CDATA when I added the web part to the web part gallery, and adding it to the page and exporting it afterwards got the result
<property name="QueryOverride" type="string"><Where><And><And><Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>Not Started</Value></Eq><Eq><FieldRef Name='Status' /><Value Type='Choice'>Not Closed</Value></Eq></Or><Leq><FieldRef Name='TargetImplDate' /><Value Type='DateTime'><Today /></Value></Leq></And><Eq><FieldRef Name='Category' /><Value Type='Choice'></Value></Eq></And></Where><OrderBy><FieldRef Name='ProcessChoice' /><FieldRef Name='TargetImplDate' /></OrderBy></property>
which worked as expected. Thanks @Andrey
其他提示
Kind of workaround, but still: deploy CQWP without this property to a page, set the property programmatically, and then export webpart to .webpart file.
I anticipate some kind of double HTML encoding nightmare like as a result.
P.S. Not tested.
P.S.S. If you will not be able to export the webpart from browser, try using programmatic approach (ExportWebPart method of SPLimitedWebPartManager).
Please keep in mind that
<where> or <Where>
tag should go on the same line with
<property name="QueryOverride" type="string">
like this
<property name="QueryOverride" type="string"><Where>
<Or>
<Eq>
<FieldRef Name="AssignedTo"/>
<Value Type="User">
<UserID/>
</Value>
</Eq>
<Membership Type="CurrentUserGroups">
<FieldRef Name="AssignedTo"/>
</Membership>
</Or>
</Where></property>
and NOT like this
<property name="QueryOverride" type="string">
<Where>
<Or>
<Eq>
<FieldRef Name="AssignedTo"/>
<Value Type="User">
<UserID/>
</Value>
</Eq>
<Membership Type="CurrentUserGroups">
<FieldRef Name="AssignedTo"/>
</Membership>
</Or>
</Where>
</property>