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

  • How come you are not using a user-column? – Robert Lindgren May 18 '16 at 6:01
2

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)

  • will the username replaced with current logged in username – Mrunal Shidurkar May 18 '16 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/… – Robert Lindgren May 18 '16 at 6:16
  • is there a possible solution without using user column – Mrunal Shidurkar May 18 '16 at 6:21
  • Not without you creating the CAML-query yourself (eg. pass in the username dynamically) – Robert Lindgren May 18 '16 at 6:26
  • do you have any reference for this condition – Mrunal Shidurkar May 18 '16 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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