Skip to content

Instantly share code, notes, and snippets.

@Aymkdn
Created October 21, 2015 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aymkdn/69dcdae30f7e12088bad to your computer and use it in GitHub Desktop.
Save Aymkdn/69dcdae30f7e12088bad to your computer and use it in GitHub Desktop.
Find the User ID from the User Information List in Sharepoint
// http://aymkdn.github.io/SharepointPlus/symbols/%24SP%28%29.html#.getUserInfo
$SP().getUserInfo("domain\\john_doe", function(info) {
if (typeof info === "string") {
console.log("Error:"+info); // there was a problem so we show it
} else
console.log("User ID = "+info.ID)
});
// query the User Information List
$SP().list("User Information List", "http://site.collection/root/dir").get({
"fields":"ID",
"where":"ImnName = 'Preferred, Name'" /* replace with the Preferred Name of the user */
},
function(d) {
console.log(d[0].getAttribute("ID"))
}
);
// or you can use a list where the User exists thru the Created By (Author), or the Modified By, or a simple people picker
// here an example using the Created By (Author) field
$SP().list("My List").get({fields:"Author",where:"Author = '[Me]'",rowlimit:1}, function(d) {
console.log($SP().getLookup(d[0].getAttribute("Author")).id)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment