Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
Reference
Query Schema
 FieldRef Element
Community Content
In this section
Statistics Annotations (8)
Collapse All/Expand All Collapse All
This page is specific to
The 2007 product release

Other versions are also available for the following:
FieldRef Element (Query)

Represents a reference to a field within a query.

<FieldRef
  Alias = "Text"
  Ascending = "TRUE" | "FALSE"
  CreateURL = "Text"
  DisplayName = "Text"
  Explicit = "TRUE" | "FALSE"
  ID = "Text"
  Key = "Text"
  Name = "Text"
  RefType = "Text"
  ShowField = "Text"
  TextOnly = "TRUE" | "FALSE"
  Type = "Text">
</FieldRef>
Attribute Description

Alias

Optional Text.

Ascending

Optional Boolean. This specifies the sort order on a FieldRef element that is defined in a view. The default value is TRUE.

CreateURL

Optional Text. Specifies the URL for the .aspx file that is used to create a Meeting Workspace site.

DisplayName

Optional Text. This attribute provides the display name of the field that is referenced.

Explicit

Optional Boolean. This attribute is only supported within the ViewFields element. TRUE if the field is explicitly declared in the view definition and is not returned in a Fields enumeration inside a view.

ID

Optional Text. Specifies the GUID that identifies the field.

Key

Optional Text. If set to Primary, specifies that the field is the primary key for its table and thus uniquely identifies each record in the table.

Name

Required Text. This attribute provides the internal name of the field that is referenced.

RefType

Optional Text. Specifies the type of reference for a field in an events list.

ShowField

Optional Text. The ShowField attribute can be set to the field name to display. By default, a hyperlinked text from the Title field of the record in the external list is displayed. But the ShowField attribute can be used to override that and display another field from the external list.

The following data types are allowed as targets of a ShowField attribute: Text, Choice, and Counter.

TextOnly

Optional Boolean. Specifies that the field contains only text values.

Type

Optional Text. Specifies the function that is applied to a totals column or a calculated column. Possible values include the following:

  • AVG   Average value. Applies to DateTimeNumber, Integer, and Currency field types.

  • COUNT   Number of items. Applies to all field types that allow aggregation.

  • MAX   Maximum value. Applies to DateTimeNumber, Integer, and Currency field types.

  • MIN   Minimum value. Applies to DateTimeNumber, Integer, and Currency field types.

  • SUM   Sum of values. Applies to Number, Integer, and Currency field types.

  • STDEV   Standard deviation. Applies to Number, Integer, and Currency field types.

  • VAR   Variance. Applies to Number, Integer, and Currency field types.

The values for the Type attribute are not case-sensitive.

None

Minimum: 0

Maximum: 1 (Unbounded within OrderBy)

The following example queries for cases where the Expires field is either null or contains a value greater than or equal to the current date.

Xml
<Query>
   <Where>
      <Or>
         <IsNull>
            <FieldRef Name="Expires" />
         </IsNull>
         <Geq>
            <FieldRef Name="Expires" />
            <Value Type="DateTime">
               <Today />
            </Value>
         </Geq>
      </Or>
   </Where>
   <OrderBy>
      <FieldRef Name="Modified" Ascending="FALSE" />
   </OrderBy>
</Query>

The next example from the Schema.xml file for contacts lists specifies fields to display in the toolbar.

Xml
<ViewFields>
   <FieldRef Name="LinkTitleNoMenu"></FieldRef>
   <FieldRef Name="FirstName"></FieldRef>
   <FieldRef Name="WorkPhone"></FieldRef>
   <FieldRef Name="Email"></FieldRef>
</ViewFields>
Community Content   What is Community Content?
Add new content RSS  Annotations
How to search by value type "lookup"?      Smartin75   |   Edit   |   Show History
<Query>
<Where>
<Eq>
<FieldRef Name="CatalogItem" LookupId="TRUE" />
<Value Type="Lookup">1</Value>
</Eq>
</Where>
</Query>
Flag as ContentBug
and how to search by value of multiple lookup ??      Ramon Torras   |   Edit   |   Show History
Please if somebody knows it. Send me a e-mail to r_torras@msn.com
Flag as ContentBug
How to display the value of a lookup field      hpf97   |   Edit   |   Show History
In the schema of a content type, I defined a view. The query is quite simple, but in the ViewFields, one fieldref is a lookup field (CheckedOutUserId).
How can I specify to display the value of this lookup field ?


Flag as ContentBug
Another how to search by value type "lookup"      Common Mollusc   |   Edit   |   Show History
<Query>
<Where>
<Eq>
<FieldRef Name="CatalogItem" LookupValue="TRUE" />
<Value Type="Lookup">Value Goes Here</Value>
</Eq>
</Where>
</Query>

This works in the same way as the LookupId but enables you to query using the column value rather than the ID of the linked column value
Tags What's this?: caml (x) howto (x) lookup (x) query (x) value (x) Add a tag
Flag as ContentBug
Querying the “Person or Group” field using SPQuery      Michael Stum   |   Edit   |   Show History
Here is how to query a person:
<where>
<eq>
<fieldref name="PersonFieldName"/>
<value type="User">User Display Name</value>
</eq>
</where>

Replace PersonFieldName with the internal Name of the Field.
The two important things here: Value Type is “User”, and the String to search for is the Display Name. So if you have a user called “John Doe” whose login is “mydomain\jdoe”, you have to search for “John Doe”, not for “mydomain\jdoe”.
There is an obvious drawback to this: What if you have two users called John Doe?

There are two workarounds. The first one: Go to the properties of the field in the list, and at the bottom you can change “Show Field” to “Account”.
This has the advantage that you can use the “domain\username” Syntax now. The drawback: The field looks bad in the list as it does now show the Login, not the Display Name with the neat presence status.

The second workaround: Use the undocumented LookupId property and search for the numeric ID:

<where>
<eq>
<fieldref name="PersonFieldName" LookupId="TRUE"/>
<value type="int">UserID</value>
</eq>
</where>

The UserID is not the “domain\username”, but the numeric internal ID (SPUser.ID). When used in a workflow, you can easily access this through workflowProperties.OriginatorUser.ID. In a Web Part, SPContext.Current.Web.CurrentUser.ID does the trick.

Tags What's this?: caml (x) Add a tag
Flag as ContentBug
A Blog Post About This Topic      AmosFiveSix1231234   |   Edit   |   Show History
Maximum ocurrences within GroupBy      Jørn Cornelius Olsen   |   Edit   |   Show History
It says that maximum occurences within OrderBy is unbounded. Apparently it is also at least 2 within GroupBy (maybe more, even unbounded?).
Tags What's this?: Add a tag
Flag as ContentBug
How to get LookupId in ViewFields?      oleg_ab   |   Edit   |   Show History

subj

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker