Come posso utilizzare queryverride in CQWP durante la distribuzione dell'istanza della web part utilizzando Elements.xml?

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/49628

Domanda

Ho bisogno di usare il CQWP con più di tre filtri, quindi utilizzerò la queryverride con una query caml come descritto qui .Non riesco a far funzionare questo quando si distribuisce l'istanza della web part usando elementi.xml i.e. ALLUSERSERSWEBPART e CDATA.

Il modo in cui l'ho fatto con i filtri normali era come quanto segue (da elementi.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...
.

Comunque QueryverRide richiede anche usando CDATA .Il problema è che non penso che 'nidificato' sono consentiti gli elementi CDATA.Ho provato codifica HTML la camm come una soluzione alternativa /approccio, ma inutilmente.

Qual è la soluzione qui?Immagino che potrei scrivere un codice ricevitore funzionalità, ma mi piacerebbe evitarlo se posso.

È stato utile?

Soluzione 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">&lt;Where&gt;&lt;And&gt;&lt;And&gt;&lt;Or&gt;&lt;Eq&gt;&lt;FieldRef Name='Status' /&gt;&lt;Value Type='Choice'&gt;Not Started&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name='Status' /&gt;&lt;Value Type='Choice'&gt;Not Closed&lt;/Value&gt;&lt;/Eq&gt;&lt;/Or&gt;&lt;Leq&gt;&lt;FieldRef Name='TargetImplDate' /&gt;&lt;Value Type='DateTime'&gt;&lt;Today /&gt;&lt;/Value&gt;&lt;/Leq&gt;&lt;/And&gt;&lt;Eq&gt;&lt;FieldRef Name='Category' /&gt;&lt;Value Type='Choice'&gt;&lt;/Value&gt;&lt;/Eq&gt;&lt;/And&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name='ProcessChoice' /&gt;&lt;FieldRef Name='TargetImplDate' /&gt;&lt;/OrderBy&gt;</property>

which worked as expected. Thanks @Andrey

Altri suggerimenti

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 &lt;Where&gt;

tag should go on the same line with

<property name="QueryOverride" type="string">

like this

 <property name="QueryOverride" type="string">&lt;Where&gt;
        &lt;Or&gt;
          &lt;Eq&gt;
            &lt;FieldRef Name="AssignedTo"/&gt;
            &lt;Value Type="User"&gt;
              &lt;UserID/&gt;
            &lt;/Value&gt;
          &lt;/Eq&gt;
          &lt;Membership Type="CurrentUserGroups"&gt;
            &lt;FieldRef Name="AssignedTo"/&gt;
          &lt;/Membership&gt;
        &lt;/Or&gt;
      &lt;/Where&gt;</property>

and NOT like this

 <property name="QueryOverride" type="string">
     &lt;Where&gt;
        &lt;Or&gt;
          &lt;Eq&gt;
            &lt;FieldRef Name="AssignedTo"/&gt;
            &lt;Value Type="User"&gt;
              &lt;UserID/&gt;
            &lt;/Value&gt;
          &lt;/Eq&gt;
          &lt;Membership Type="CurrentUserGroups"&gt;
            &lt;FieldRef Name="AssignedTo"/&gt;
          &lt;/Membership&gt;
        &lt;/Or&gt;
      &lt;/Where&gt;
</property>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top