Elements.xml을 사용하여 웹 파트 인스턴스를 배포 할 때 CQWP에서 QuearyOverRide를 사용하려면 어떻게해야합니까?
-
09-12-2019 - |
문제
CQWP를 3 개 이상의 필터로 사용해야하므로 여기에 설명 된 .elements.xml i.e. allUsersWebPart와 CDATA를 사용하여 웹 파트 인스턴스를 배포 할 때 작동하려면이 옵션을 사용할 수 없습니다.
정상적인 필터로 한 방식이 다음과 같았습니다 (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 인코딩 html 인코딩 am을 해결 과정 /접근 방식,하지만 아무 소용도 없어.
여기에 해결책은 무엇입니까?나는 몇 가지 기능 수신자 코드를 작성할 수 있었지만, 할 수 있다면 나는 그것을 피하고 싶습니다.
해결책 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>