本文介绍了将用户添加到组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我使用以下代码成功将用户添加到sharepoint中的分组。 < script type =" text / javascript"> $ SP.SOD.executeFunc('sp.js','SP.ClientContext',retrieveListItems); function retrieveListItems(){ var clientContext = new SP.ClientContext.get_current(); var oList = clientContext.get_web()。get_lists()。getByTitle('MyTestList'); var camlQuery = new SP.CamlQuery(); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); $ clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded),Function.createDelegate(这个,这个.onQu eryFailed)); } 函数onQuerySucceeded(sender,args){ var listItemEnumerator = collListItem.getEnumerator(); while(listItemEnumerator.moveNext()){ var oListItem = listItemEnumerator.get_current(); var siteCollUrl = oListItem.get_item('siteCollUrl'); addUserToSharePointGroup(siteCollUrl); } }  &NBSP; &NBSP; &NBSP; &NBSP;    function addUserToSharePointGroup(siteUrl){   &NBSP; var clientContext = new SP.ClientContext(siteUrl);   &NBSP; var collGroup = clientContext.get_web()。get_siteGroups();   &NBSP; var oGroup = collGroup.getById(7);   &NBSP; var userCreationInfo = new SP.UserCreationInformation();   &NBSP; userCreationInfo.set_email('[email protected]');   &NBSP; userCreationInfo.set_loginName('DOMAIN \ alias');   &NBSP; userCreationInfo.set_title('John');   &NBSP; this.oUser = oGroup.get_users()。add(userCreationInfo);   &NBSP; clientContext.load(oUser);   &NBSP; clientContext.executeQueryAsync(Function.createDelegate(this,this.onAddSucceeded),Function.createDelegate(this,this.onQueryFailed)); $ } function onAddSucceeded(){   &NBSP; console.log(this.oUser.get_title()+" added。"); } 函数onQueryFailed(sender,args){   &NBSP; alert('请求失败。'+ args.get_message()+'\ n'+ args.get_stackTrace()); } < / script> 但是在我的环境中,我的登录名就像i:0#.w | test | kkumar.with out pass 域名如何添加用户。请帮助。 问候, PraveenHi all,I have used below code to add users to group in sharepoint successfully.<script type="text/javascript">SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);function retrieveListItems(){var clientContext = new SP.ClientContext.get_current();var oList = clientContext.get_web().get_lists().getByTitle('MyTestList');var camlQuery = new SP.CamlQuery();this.collListItem = oList.getItems(camlQuery);clientContext.load(collListItem);clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));}function onQuerySucceeded(sender, args){var listItemEnumerator = collListItem.getEnumerator();while (listItemEnumerator.moveNext()) {var oListItem = listItemEnumerator.get_current();var siteCollUrl=oListItem.get_item('siteCollUrl');addUserToSharePointGroup(siteCollUrl);}}            function addUserToSharePointGroup(siteUrl){    var clientContext = new SP.ClientContext(siteUrl);    var collGroup = clientContext.get_web().get_siteGroups();    var oGroup = collGroup.getById(7);    var userCreationInfo = new SP.UserCreationInformation();    userCreationInfo.set_email('[email protected]');    userCreationInfo.set_loginName('DOMAIN\alias');    userCreationInfo.set_title('John');    this.oUser = oGroup.get_users().add(userCreationInfo);    clientContext.load(oUser);    clientContext.executeQueryAsync(Function.createDelegate(this, this.onAddSucceeded), Function.createDelegate(this, this.onQueryFailed));}function onAddSucceeded() {    console.log(this.oUser.get_title() + " added.");}function onQueryFailed(sender, args) {    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());}</script>But in my environment my login name is like i:0#.w|test|kkumar.with out passing  domain name how to add users.Please help.regards,Praveen推荐答案 您好,您不能在代码中对域名进行硬编码并只传递用户名吗?you cannot hard code the domain name in code and pass only username? 这篇关于将用户添加到组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 01:30