SharePoint 2013 Javascript 插入带有查找字段的项目

标签 sharepoint sharepoint-2013

我尝试使用以下代码在 SharePoint 2013 中仅通过 Javascript 添加列表项;

function createListItem() {

    var clientContext = new SP.ClientContext.get_current();

    var oList = clientContext.get_web().get_lists().getByTitle('CrewNoticesAudit');

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

    oListItem.set_item('Title', 'My New Item!');
    oListItem.set_item('NoticeId', 1);  // THIS IS A LOOKUP VALUE
    oListItem.set_item('User', 'administrator');
    oListItem.set_item('TimeStamp', new Date());
    oListItem.set_item('AuditType', 'Open');

    oListItem.update();

    clientContext.load(oListItem);

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

function onQuerySucceeded() {
    alert('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

我遇到的问题是,NoticeId 是一个查看不同列表的查找值。我需要做一些不同的事情来设置项目的查找值吗?

更新:抱歉,已破解。第二次google更有成果。

如果其他人遇到困难,您需要创建一个查找字段。

    var noticeIdLookup = new SP.FieldLookupValue();
    noticeId.set_lookupId(noticeId);

最佳答案

正确的方法是:

var lkfieldsomthing = new SP.FieldLookupValue();

lkfieldsomthing.set_lookupId(ID_VALUE); //WHERE ID_VALUE is the unique ID 

然后在设置时您可以使用

listItem.set_item("LOOKUP_COLUMN_NAME", lkfieldsomthing )

关于SharePoint 2013 Javascript 插入带有查找字段的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21209228/

相关文章:

java - 如何从安卓连接共享点?

jQuery 和 CSS 在 Sharepoint 2013 中不起作用

javascript - 使用索引作为 ID VueJS 的动态模态

javascript - 如何使用 javascript 批准任务?

jquery - 使用自动完成功能筛选 SharePoint 中 jQuery 列表中的列表

sharepoint - 我可以更改链接到共享点列表中带有编辑菜单的项目的列吗?

sharepoint - AllowUnsafeUpdates 的最佳模式

javascript - sharepoint 剩余查找值

sharepoint - 如何在服务器上定位Sh​​arepoint 文档库源页面?

javascript - 将 jquery 事件监听器添加到一系列独特的元素