gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:36:43 24 4
gpt4 key购买 nike

我尝试使用以下代码在 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/

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