¿Cómo puedo obtener el correcto SPFIVEUSERVALUE para usar SPSITEDAQUERY para agregar tareas para un determinado usuario?

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

  •  10-12-2019
  •  | 
  •  

Pregunta

Estoy tratando de reunir todas las tareas de un cierto tipo de contenido para un determinado usuario.Para lograr esto, estoy usando un SPSITEDAQUERY, que se parece a esto:

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);

Funciona bien si solo quiero filtrar para el tipo de contenido, pero el filtrado para el usuario falla.

Aquí es lo que creo que es el problema. El campo Asignado contiene valores que se parecen a este

17;#TestUser01

Pero mi nombre de inicio de sesión regular contiene la cadena de reclamaciones y el dominio y se ve así

i:0#.w|test\TestUser01

Intenté crear el SPFIVEUSERVALUE para obtener la misma cadena de usuario que se encuentra en el campo Asignado. Así:

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

.. Pero entonces solo obtengo un valor que se ve así:

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

.. y todavía no obtengo resultados de mi consulta.

¿Cómo puedo obtener la cadena correcta para ejecutar mi consulta?

¿Fue útil?

Solución

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
scroll top