一、操作当前用户
![](https://i-blog.csdnimg.cn/blog_migrate/3d6d7e77f17dddb94d884c210eab170c.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/ac4099902f020aba353793f8b98f907a.gif)
//Load current user info
function LoadCurUser()
{
var curUser;
curUser = curWeb.get_currentUser();
curContext.load(curUser);
curContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded() {
$("#hdUserName").text(curUser.get_title());
$("#txtReqName").text(curUser.get_title());
//Load mail configuration
if (wfType)
LoadMailConfig();
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
}
二、操作其它用户
![](https://i-blog.csdnimg.cn/blog_migrate/f3ba89a7c2e48c0602630c074801c743.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/d35e065de5330864303508c8dedb66a1.gif)
function LoadUserByID(userId)
{
var camlQuery = new SP.CamlQuery();
var caml = '<View><Query><Where><Eq><FieldRef Name=\'ID\'/>'
+ '<Value Type=\'Number\'>' + userId + '</Value></Eq>'
+ '</Where></Query><RowLimit>1</RowLimit></View>';
camlQuery.set_viewXml(caml);
var userList = curWeb.get_siteUserInfoList();
var users = userList.getItems(camlQuery);
curContext.load(users);
curContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(sender, args) {
var user = users.itemAt(0);
var userName = user.get_item('UserName');
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
}
三、操作用户组
![](https://i-blog.csdnimg.cn/blog_migrate/0281d43d2db95c95863b8207839e213f.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/f24d68defba7e0bdacda10f80579ca7c.gif)
function retrieveAllUsersAllGroupsSpecificProperties() {
var clientContext = new SP.ClientContext(siteUrl);
this.collGroup = clientContext.get_web().get_siteGroups();
clientContext.load(collGroup, 'Include(Title,Id,Users.Include(Title,LoginName))');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var userInfo = '';
var groupEnumerator = collGroup.getEnumerator();
while (groupEnumerator.moveNext()) {
var oGroup = groupEnumerator.get_current();
var collUser = oGroup.get_users();
var userEnumerator = collUser.getEnumerator();
while (userEnumerator.moveNext()) {
var oUser = userEnumerator.get_current();
this.userInfo += '\nGroup ID: ' + oGroup.get_id() +
'\nGroup Title: ' + oGroup.get_title() +
'\nUser: ' + oUser.get_title() +
'\nLogin Name: ' + oUser.get_loginName();
}
}
alert(userInfo);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
四、使用get_fieldValues()获取其它字段信息
Get Name:
var obj = item.get_fieldValues().Name;
Get UserName:
var obj = item.get_fieldValues().UserName;
Get Email:
var obj = item.get_fieldValues().Email;
Get First Name:
var obj = item.get_fieldValues().FirstName;
Get Job Title:
var obj = item.get_fieldValues().JobTitle;
Get Mobile Phone:
var obj = item.get_fieldValues().MobilePhone;
Get Work Phone:
var obj = item.get_fieldValues().WorkPhone;
Get Notes:
var obj = item.get_fieldValues().Notes;
Get Picture:
var obj = item.get_fieldValues().Picture;
Get SIP Address:
var obj = item.get_fieldValues().SipAddress;
Get Title:
var obj = item.get_fieldValues().Title;
Get Department:
item.get_fieldValues().Department;
Get Web Site:
item.get_fieldValues().WebSite;
Get TimeZone:
item.get_fieldValues().TimeZone;