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

标签 javascript sharepoint

我想创建一个共享点任务并在 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/

相关文章:

Javascript:将 var 传递给对象文字

javascript - 如何在不位于确切页面的情况下禁用 Sharepoint Web 部件?

sharepoint - 在线使用SharePoint 2010进行练习

java - 如何将 Sharepoint 日期从十六进制解析为 java.util.Date

javascript - AngularJS:尝试使用服务,出现错误 "cannot read property ',然后是“未定义”

javascript - 一次为超链接添加不同的样式(tagcloud/linkcloud)

javascript - 使用 Angular 13 使用 js-xlsx 读取本地 Excel 文件?

javascript - 有什么方法可以防止在单例实例中覆盖/覆盖函数/变量?

SharePoint/GetVersionCollection - 如何识别哪个版本?

wcf - 如何在 .NET 3.5 运行时的 Visual Studio 2010 SP1 中启动 WCF 服务主机?