admin管理员组文章数量:1278881
Is there a way to edit a multivalue lookup field using the JavaScript Client Object Model? I need to remove one or more lookup values and, eventually, add one or more values.
I search everywhere, I read MSDN documentation, ..., I also take a look under my desk!
Thanks.
Is there a way to edit a multivalue lookup field using the JavaScript Client Object Model? I need to remove one or more lookup values and, eventually, add one or more values.
I search everywhere, I read MSDN documentation, ..., I also take a look under my desk!
Thanks.
Share Improve this question asked Mar 27, 2014 at 17:19 SeahorseSeahorse 351 gold badge1 silver badge5 bronze badges2 Answers
Reset to default 6Multiple-Column Lookup
value is represented as an array of SP.FieldLookupValue objects.
How to read multiple Lookup
field value
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var listItem = list.getItemById(1);
context.load(listItem);
context.executeQueryAsync(
function() {
var lookupVals = listItem.get_item(fieldName); //get multi lookup value (SP.FieldLookupValue[])
for(var i = 0;i < lookupVals.length;i++) {
console.log(lookupVals[i].get_lookupId()); //print Id
console.log(lookupVals[i].get_lookupValue()); //print Value
}
},
function(sender,args){
console.log(args.get_message());
}
);
How to update multiple Lookup
field value
For updating multiple Lookup value you need to specify value of type SP.FieldLookupValue[]
. Note, SP.FieldLookupValue
could be initialized by specifying LookupId
only.
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var listItem = list.getItemById(1);
var lookupVals = [];
//set 1st Lookup value
var lookupVal1 = new SP.FieldLookupValue();
lookupVal1.set_lookupId(1);
lookupVals.push(lookupVal1);
//set 2nd Lookup value
var lookupVal2 = new SP.FieldLookupValue();
lookupVal2.set_lookupId(2);
lookupVals.push(lookupVal2);
listItem.set_item(fieldName,lookupVals);
listItem.update();
context.executeQueryAsync(
function() {
console.log('Multi lookup field has been updated');
},
function(sender,args){
console.log(args.get_message());
}
);
You can get lookup values via js this way:
clientContext.executeQueryAsync(function () {
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
chartX.push(oListItem.get_item(xAxisName));
}
lookupValue1= chartX["0"].$1g_1;
lookupValue2= chartX["1"].$1g_1;
本文标签: Sharepoint 2013 Multivalue lookup field with JavaScriptStack Overflow
版权声明:本文标题:Sharepoint 2013. Multivalue lookup field with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741285020a2370221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论