2

I'm using SPServices to query a SharePoint Online (2013) list that contains a Person or Group column. (This column is set to allow selection of People Only, in case that matters.)

The query used is below.

<Query>
    <Where>
        <Eq>
            <FieldRef Name='ComponentID'></FieldRef>
            <Value Type='Number'>151</Value>
        </Eq>
    </Where>
    <QueryOptions><ExpandUserField>TRUE</ExpandUserField></QueryOptions>
</Query>

<ViewFields>
    <FieldRef Name='RequiredApprovers' />
    // some other fields of other types
</ViewFields>

The response I get is below.

[userID = 6];#Skip Baker,[account = #i:0#.f|membership|sbaker@example.com],#sbaker@example.com,#sbaker@example.com,#Skip Baker,#[Photo URL],#[Department Name],#[Job Title]

I want to parse the string into a User data object, which I know how to do. However, I don't know what all of the parts of the string are, and I don't want to rely on something being an email address when it's really a domain user name, etc. I've used brackets to indicate the parts I believe I understand. Can anyone tell me what the other parts of this string are?

  • Can you update the SPServices query you are using? It depends on what all information you are requesting. – Amal Hashim Apr 21 '15 at 17:56
  • Happily - one sec :) – Skip Apr 21 '15 at 18:04
1

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.expanduserfield(v=office.14).aspx

Whether to use special rendering for user field values that makes them include the login name, e-mail address, Session Initiation Protocol (SIP) address, and title, when present, which causes a user field to behave as a multilookup field.

You don't need to manually parse data

function userToJsonObject(s) {
    if (s.length === 0) {
        return null;
    } else {
        var thisUser = s.split(";#"); 
        var thisUserExpanded = thisUser[1].split(",#")
        if(thisUserExpanded.length == 1) {
            return {userId: thisUser[0], userName: thisUser[1]}
        } else {
            return {
                userId: thisUser[0], 
                userName: thisUserExpanded[0].replace( /(,,)/g, ","), 
                loginName: thisUserExpanded[1].replace( /(,,)/g, ","), 
                email: thisUserExpanded[2].replace( /(,,)/g, ","), 
                sipAddress: thisUserExpanded[3].replace( /(,,)/g, ","), 
                title: thisUserExpanded[4].replace( /(,,)/g, ",")
            }
        }
    }
}

http://spservices.codeplex.com/workitem/10071

| improve this answer | |
  • That function doesn't actually return all the parts of the string I provided, so manual parsing is still required. However, I was able to find the unknown property names I was looking for inside the function. Thanks :) – Skip Apr 21 '15 at 19:00

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.