gpt4 book ai didi

javascript - 使用 Javascript 对象模型在 SharePoint 任务上设置 "Assigned To"

转载 作者:行者123 更新时间:2023-12-03 06:23:30 25 4
gpt4 key购买 nike

我想创建一个共享点任务并在 javascript 对象模型中将其分配给我自己(当前用户)。我有下面的代码,但我认为我需要设置 spusercollection 对象,而不是设置特定用户。但是,我似乎无法在任何地方找到如何执行此操作的任何示例。

  var clientContext = new SP.ClientContext(siteUrl);
var web = clientContext.get_web();
var oList = web.get_lists().getByTitle('Tasks');

var itemCreateInfo = new SP.ListItemCreationInformation();
oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item("Title","My New Item!");
oListItem.set_item("Assigned To", _spPageContextInfo.userLoginName);
oListItem.update();

clientContext.load(oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);

最佳答案

您需要执行如下操作:

<script type="text/ecmascript">

ExecuteOrDelayUntilScriptLoaded(updateUserField, "sp.js");

function updateUserField(){
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('ListA');
var item = list.getItemById(1);

var assignedToVal = new SP.FieldUserValue();
assignedToVal.set_lookupId(1); //specify User Id
item.set_item("UserField",assignedToVal);
item.update();

ctx.executeQueryAsync(
function() {
console.log('Updated');
},
function(sender,args) {
console.log('An error occurred:' + args.get_message());
}
);
}
</script>

引用:

https://social.technet.microsoft.com/Forums/en-US/9fac5d83-770f-4d03-8881-f301ea83d8cb/update-person-or-group-field-in-sharepoint-list-using-javascript-object-model?forum=sharepointdevelopmentprevious

谢谢,贾米尔

关于javascript - 使用 Javascript 对象模型在 SharePoint 任务上设置 "Assigned To",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38755618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com