本文介绍了设置“已分配给”使用Javascript对象模型的SharePoint任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个sharepoint任务,并将其分配给我自己(当前用户)的javascript对象模型。我有下面的代码,但我认为我需要设置一个spusercollection对象,而不是设置一个特定的用户。但是,我似乎无法找到任何有关如何执行此操作的示例。
I want to create a sharepoint task and assign it to myself (current user) wtihin the javascript object model. I have the code below, but I think instead of setting a particular user i need to set a spusercollection object. However, I can't seem to find any examples anywhere of how to do this.
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>
参考:
谢谢,
Jameel
Thanks,Jameel
这篇关于设置“已分配给”使用Javascript对象模型的SharePoint任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!