Come posso ottenere il corretto SpfieldUSERVALUE per utilizzare SPSiteDataTaCequery per aggregare le attività per un determinato utente?

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

  •  10-12-2019
  •  | 
  •  

Domanda

Sto cercando di raccogliere tutti i compiti di un determinato tipo di contenuto per un certo utente.Per realizzare questo, sto usando una SPSiteDatatataTequery che assomiglia a questo:

string where = String.Format(@"<Where>
                                        <And>
                                            <BeginsWith>
                                                <FieldRef Name='ContentTypeId'/>
                                                <Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
                                            </BeginsWith>
                                            <Eq>
                                                <FieldRef Name='AssignedTo'/>
                                                <Value Type='Text'>{0}</Value>
                                            </Eq>
                                        </And>
                                     </Where>", userValue.ToString());
query.Query = where;
DataTable results = web.GetSiteData(query);
.

funziona bene se voglio solo filtrare per il tipo di contenuto, ma il filtraggio per l'utente fallisce.

Ecco cosa penso che il problema sia. Il campo Assegnato contiene valori che assomigliano a questo

17;#TestUser01
.

Ma il mio loginname regolare contiene la stringa di rivendicazioni e il dominio e sembra questo

i:0#.w|test\TestUser01
.

Ho provato a creare lo spfielduservalue per ottenere la stessa stringa utente che si trova nel campo assegnato .. così:

SPFieldUserValue userValue = new SPFieldUserValue(web, SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.LoginName);
.

.. Ma poi ho solo un valore che assomiglia a questo:

17;#i:0#.w|test\TestUser01
.

.. E non ottengo ancora risultati dalla mia query ..

Come posso ottenere la stringa corretta per eseguire la mia query?

È stato utile?

Soluzione

By changing the CAML like this:

string where = @"<Where>
                                        <And>
                                            <BeginsWith>
                                                <FieldRef Name='ContentTypeId'/>
                                                <Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
                                            </BeginsWith>
                                            <Eq>
                                                <FieldRef Name='AssignedTo' LookupId='TRUE' />
        <Value Type='Integer'><UserID /></Value>
                                            </Eq>
                                        </And>
                                     </Where>";
query.Query = where;
DataTable results = web.GetSiteData(query);

it will fetch for current user :)

If you need to specify another user you can use:

string where = String.Format(@"<Where>
                                        <And>
                                            <BeginsWith>
                                                <FieldRef Name='ContentTypeId'/>
                                                <Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
                                            </BeginsWith>
                                            <Eq>
                                                <FieldRef Name='AssignedTo' LookupId='TRUE' />
                                                <Value Type='Integer'>{0}</Value>
                                            </Eq>
                                        </And>
                                     </Where>", userValue.ToString());
query.Query = where;
DataTable results = web.GetSiteData(query);

and just make sue you have the ID of the user in userValue

Altri suggerimenti

The CAML Query for fetching the values for current user is:

"<Where><Eq><FieldRef Name='AssignedTo' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq></Where>";

And for another user it should be as mentioned by @Robert.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top