0

How can we pass current user login name in caml query where condition?

I want to get only the list items pertaining to logged in user. For this I need to pass loginName of current user in caml query.

Please help.

I have a function to get username: var loginName = currentUser.get_loginName(); var UserName = currentUser.get_title();

I want to pass LoginName or UserName variables, in my Caml Query in Where Clause.

For eg: If the Author=LoginUser , I want the records to be retrieved.

Below is my query:

camlQueryAppPend.set_viewXml
('<View>' +
'<Query>' +
'<OrderBy>' +
'<FieldRef Name=\'Modified\' Ascending=\'FALSE\'/> ' +
'</OrderBy>' +
'<Where>' +
<Eq><FieldRef Name=\'Author\' />
<Value Type=\'Text\'>\'+ UserName + \'</Value>
</Eq>' +
'</Where>' +
'</Query>' +
'</View>');

Please suggest.

user1841395
  • 29
  • 1
  • 1
  • 6

1 Answers1

1

To be able to filter for the current user, the condition of your CAML query should look like this:

<Where>
    <Eq>
        <FieldRef Name='InternalNameOfYourPersonField' />
        <Value Type='Integer'><UserID/></Value>
    </Eq>
</Where

You don't need to use the login name at all.

pholpar
  • 1,725
  • 2
  • 14
  • 23