使用JavaScript将当前用户附加到任务列表 [英] Append current user to a task list using JavaScript

查看:92
本文介绍了使用JavaScript将当前用户附加到任务列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SP设计师表单,可以自定义显示任务字段中的表单。 




多个用户应该有能力申请这个任务和我能够更新分配给当前用户。




(用户字段 - 允许多个标记开启)



另一个用户还应该能够申请到某个日期,并且我无法使用java脚本将这个新的当前用户附加到指定的字段。它会覆盖旧值。请帮忙!



审批人应该能够看到所有试图申请任务的用户,他应该有能力选择一,关闭任务。



  &NBSP; < script type =" text / javascript">

  var currentUserID;

&NBSP; function CandidateApply(){

  

   var siteUrl ="< XXX>"

  

  &NBSP; var clientContext = new SP.ClientContext(siteUrl);

  &NBSP; var oList = clientContext.get_web()。get_lists()。getByTitle(" TaskListName");

  &NBSP;  



  &NBSP; var CurrentItemID = GetUrlKeyValue(" ID")

  &NBSP; this.oListItem = oList.getItemById(CurrentItemID);

  &NBSP; oListItem.set_item(& AssignedTo&',currentUserID );

     oListItem.update();



  &NBSP; clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceededApply),Function.createDelegate(this,this.onQueryFailed));

   }

 





解决方案

这是你的代码


http://rhogan.ie/insert-multiple-users-into-sharepoint-people-lookup-column-using-jsom/

 function InsertUsers(){

var ctx = new SP.ClientContext(appWebUrl);
var appCtxSite = new SP.AppContextSite(ctx,hostWebUrl);

var web = appCtxSite.get_web(); //获取Web

var oList = web.get_lists()。getByTitle('RaysTestList');

var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);

//获取用户信息
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDivExample_TopSpan;
var users = peoplePicker.GetAllUserInfo();
//用于存储用户的数组
var userObjs = [];
var userName ="" ;;
//循环选择器并将它们添加到数组
for(var i = 0; i& lt; users.length; i ++){
userName = users [i] [" ;说明与QUOT;];
userObjs.push(SP.FieldUserValue.fromUser(userName));
}

oListItem.set_item('Title','Rays Demo");
oListItem.set_item('UsersGalore',userObjs);

oListItem.update();

ctx.load(oListItem);

ctx.executeQueryAsync(Function.createDelegate(this,onQuerySucceeded),Function.createDelegate(this,onQueryFailed));
}
//当时间请求成功时...
函数onQuerySucceeded(){

//成功!


("#output")。html(" Item added");

}
//当时间请求失败时...
函数onQueryFailed(sender,args){

//糟糕!

("#output")。html(" Item failed");
}


I have a SP designer form which is customized to display a form from Task fields. 


Multiple Users should have the ability to apply for this task and I am able to update the assigned to to the current user.


(user field - with allow multiple flag on)

Another user should also have the ability to apply till a certain date and i am not able to append this new current user to the assigned to field using java script. It overwrites the old value. Please help!

The approver should be able to see all the users who tried to apply for the task and he should have the ability to choose one and close the task.

    <script type="text/javascript">
  var currentUserID ;
  function CandidateApply() {
  
   var siteUrl = "<XXX>"
  
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle("TaskListName");
     

    var CurrentItemID = GetUrlKeyValue("ID")
    this.oListItem = oList.getItemById(CurrentItemID );
    oListItem.set_item(&apos;AssignedTo&apos;, currentUserID  );
    oListItem.update();

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededApply), Function.createDelegate(this, this.onQueryFailed));
   }
 

解决方案

Here is your code

http://rhogan.ie/insert-multiple-users-into-sharepoint-people-lookup-column-using-jsom/

function InsertUsers() {

var ctx = new SP.ClientContext(appWebUrl);
var appCtxSite = new SP.AppContextSite(ctx, hostWebUrl);

var web = appCtxSite.get_web(); //Get the Web

var oList = web.get_lists().getByTitle('RaysTestList');

var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);

//Get User info
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDivExample_TopSpan;
var users = peoplePicker.GetAllUserInfo();
//Array to store users
var userObjs = [];
var userName = "";
//Cycle through the picker and add them to array
for (var i = 0; i &lt; users.length; i++) {
userName = users[i]["Description"];
userObjs.push(SP.FieldUserValue.fromUser(userName));
}

oListItem.set_item('Title', "Rays Demo");
oListItem.set_item('UsersGalore', userObjs);

oListItem.update();

ctx.load(oListItem);

ctx.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
}
//When the time request succeeds...
function onQuerySucceeded() {

//Success!


("#output").html("Item added"); } //When the time request fails... function onQueryFailed(sender, args) { //Oops!


("#output").html("Item failed"); }


这篇关于使用JavaScript将当前用户附加到任务列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆