0

In my hosted app I have one text field which contains username. I want to apply filter on a view which on filtering gives me data related to current user.

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="Name" Required="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" FromBaseType="TRUE" ColName="nvarchar1" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Version="1" RowOrdinal="0" />

I can only have above text field to apply filter. How to apply caml query for this situations

1
  • How come you are not using a user-column? Commented May 18, 2016 at 6:01

1 Answer 1

3

A CAML query for that would look something like this

<View>
    <Query>
        <Where>
            <Contains>
                <FieldRef Name='Title'/>
                <Value Type='Text'>username</Value>
            </Contains>
        </Where>
    </Query>
</View>

But I do wonder why you are not using a field of user type, to be able to do a better filtering (and a better GUI for the end users)

8
  • will the username replaced with current logged in username Commented May 18, 2016 at 6:11
  • You would need to manually place the current users login name there in your scenario. If you instead use a user column you could put in <UserID /> as outlined here sharepoint.stackexchange.com/questions/35975/… Commented May 18, 2016 at 6:16
  • is there a possible solution without using user column Commented May 18, 2016 at 6:21
  • Not without you creating the CAML-query yourself (eg. pass in the username dynamically) Commented May 18, 2016 at 6:26
  • do you have any reference for this condition Commented May 18, 2016 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.