0

I'm trying to get a single field from a list. The list has columns like this:

Office365Account - Type: Person

Email Address - Type: Email

Manager - Type: Person

Basically what I want to do is find the manager associated with the current user of the system.

In SQL I'd do it something like this:

SELECT Manager FROM organizationContactsList WHERE Office365Account = currentuser

I'm pretty sure a CAML query is what I need to (or at least should) use, but I've just begun with SharePoint/SharePoint App programming and the structure of CAML queries baffle me. Any pointers on what this would look like in CAML?

2
  • Are you using onpremise sharepoint or sharepoint online?
    – Aanchal
    Commented Jun 6, 2014 at 14:52
  • SharePoint Online; this is for a App written using the JavaScript Object Model.
    – Ectropy
    Commented Jun 6, 2014 at 14:53

2 Answers 2

2

You can use the following CAML query :

<Where>
  <Eq>
    <FieldRef Name="Office365Account" />
    <Value Type="Integer">
      <UserID />
    </Value>
  </Eq>
</Where>
7
  • Ah this makes more sense. And to get the UserID for the current user I'd do: currentContext.get_web().get_currentUser().get_id() I think this will solve my issue.
    – Ectropy
    Commented Jun 6, 2014 at 15:02
  • For current user you don't need to pass an ID. You can try as it is. If there is problem you can try with ID also.
    – Aanchal
    Commented Jun 6, 2014 at 15:03
  • Oh I see. <UserID /> assumes that you're talking about the integer userid for the current user, if I'm not mistaken.
    – Ectropy
    Commented Jun 6, 2014 at 15:04
  • Yes, i am assuming Office365Account is a User field.
    – Aanchal
    Commented Jun 6, 2014 at 15:05
  • Very good. That simplifies things! (It is a User field in my case.)
    – Ectropy
    Commented Jun 6, 2014 at 15:07
1

You can certainly use CAML for this, but a simple REST call would spit out the manager if you supply the user's claim.

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@a,propertyName='Manager')?@a='{userClaim}'

There's a good blog post about pulling User Profile Properties from REST here: http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

3
  • Ah very good. I'll keep this in mind too, and determine which best fits my needs.
    – Ectropy
    Commented Jun 6, 2014 at 18:09
  • Oh I see, they have to have a manager associated with their actual account's properties for a query like this to work. In my case our organization doesn't have that manager field filled out, and instead we're using a separate list that groups people and their managers.
    – Ectropy
    Commented Jun 6, 2014 at 20:21
  • If you can't use people service then you can just use a REST query to your lookup list; still arguably more efficient than CAML (and a more future proof solution given the deprecation of the SOAP services).
    – webdes03
    Commented Jun 8, 2014 at 13:43

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.