Enhanced userToJsonObject for use when ExpandUserField = True

May 23, 2012 at 7:18 PM
Edited May 23, 2012 at 7:23 PM

In doing some research on how to get more user fields, I found in your documentation how to set the CAMLQueryOptions option in order to get all the info available to you.  Unfortunately, when you convert the response to Json, you only get userId and userName as properties and not the additional Name, LoginName, email, SIP Address, and Title fields.  So I have changed the userToJsonObject in my own implementation to account for this extra data if it exists.  I referenced this posting to determine the schema of additional data. See below:

 

    function userToJsonObject(s) {
        if (s.length === 0) {
            return null;
        } else {
            //updates to handle expanded user information
            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: thisUser[1], 
			name: thisUserExpanded[0].replace( /(,,)/g, ","), 
			loginName: thisUserExpanded[1].replace( /(,,)/g, ","), 
			email: thisUserExpanded[2].replace( /(,,)/g, ","), 
			sipAddress: thisUserExpanded[3].replace( /(,,)/g, ","), 
			title: thisUserExpanded[4].replace( /(,,)/g, ",")
		}
            }           
            //formerly userId and userName are the only fields returned
            //  return { userId: thisUser[0], userName: thisUser[1] };            
        }
    }
Coordinator
May 24, 2012 at 2:46 AM

Jeff:

Thanks for this. When I created the SPXmlToJson function, I wasn't sure how much people would use it, so I didn't worry too much about edge conditions.

I'll look at this and try to get it into a future release.

M.

Coordinator
May 24, 2012 at 2:46 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
May 31, 2012 at 12:21 PM

FYI - I've added this into the latest alpha. Check the work item link above for details. Let me know if you get a chance to try it out!

M.