Created
October 21, 2015 06:42
-
-
Save Aymkdn/69dcdae30f7e12088bad to your computer and use it in GitHub Desktop.
Find the User ID from the User Information List in Sharepoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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