更新另一个id为查阅列的字段 [英] Update another field with an id of a lookup column
本文介绍了更新另一个id为查阅列的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含大约1000列的列表,我需要能够在同一列表中使用另一个查找字段的lookupid预填充另一个字段
< pre class ="prettyprint">
我有一个包含大约1000列的列表,我需要能够使用另一个的lookupid预填充另一个字段同一个列表中的查找字段
我使用时收到错误:
var LookUpColumnId = oListItem.get_item('LookUpColumn')。get_lookupId();
错误:
未捕获错误:属性或字段尚未初始化。尚未请求或请求尚未执行。
请参阅下面的代码:
函数onUpdateSucceeded(){
var itemEnumerator = items.getEnumerator();
while(itemEnumerator.moveNext()){
var item = itemEnumerator.get_current();
//你现在有了你想要的物品!
//console.log(item.get_item("ID"));
IDs.push(item.get_item(" ID")));
}
console.log(IDs);
var siteUrl ='/ sites / Dev /';
var clientContext = new SP.ClientContext(siteUrl);
oList = clientContext.get_web()。get_lists()。getByTitle('Test');
var itemsToLoadForUpdate = Array(); //保持我们的"当前"要更新的项目
var totalItemsToUpdate = 900;
var limitItemsToUpdate = 50; //每90个项目更新
var batchUpdatesCounter = Math.ceil(totalItemsToUpdate / limitItemsToUpdate); //如果需要计算剩余的批量更新
var restItemsToUpdate = 0; //之后要更新的项目(见下文)
for(var i = 0; i< IDs.length; i ++){
var oListItem = oList.getItemById(IDs [i] );
/ *新添加项目的查找ID * /
// var lookupFieldValue = oListItem.get_item('LookUpColumn');
// var lookupId = lookupFieldValue.get_lookupId();
//console.log(LookUpColumnId);
// alert(lookupFieldValue);
//这有效,但是当我在上面设置lookupId时,我不能;甚至得到lookupId
oListItem.set_item('LookUpID',1);
oListItem.update();
itemsToLoadForUpdate [i] = oListItem;
clientContext.load(itemsToLoadForUpdate [i]);
if(i& i%limitItemsToUpdate == 0){
console.log('Updating'+ limitItemsToUpdate +'items ...');
clientContext.executeQueryAsync(this.onUpdateSucceeded,this.onUpdateFailed);
restItemsToUpdate = 0;
}
else {//要更新的剩余项目
restItemsToUpdate = i%limitItemsToUpdate;
}
}
if(restItemsToUpdate){
//console.log('Updating rest items ...');
console.log('Updating'+ restItemsToUpdate +'items ...');
clientContext.executeQueryAsync(this.onUpdateSucceeded,this.onUpdateFailed);
}
}
预付款
$
先谢谢
解决方案
来自MS的任何人都没有发言
I have a list with around 1000 columns and I need to be a able to prepopulate another field with a lookupid of another lookup field on the same list
I have a list with around 1000 columns and I need to be a able to prepopulate another field with a lookupid of another lookup field on the same list I am getting error when I use: var LookUpColumnId = oListItem.get_item('LookUpColumn').get_lookupId(); Error: Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. See snippet below: function onUpdateSucceeded() { var itemEnumerator = items.getEnumerator(); while (itemEnumerator.moveNext()) { var item = itemEnumerator.get_current(); // You now have the item you were looking for! //console.log(item.get_item("ID")); IDs.push(item.get_item("ID")); } console.log(IDs); var siteUrl = '/sites/Dev/'; var clientContext = new SP.ClientContext(siteUrl); oList = clientContext.get_web().get_lists().getByTitle('Test'); var itemsToLoadForUpdate = Array(); // Holds our "current" items to update var totalItemsToUpdate = 900; var limitItemsToUpdate = 50; // Update every 90 items var batchUpdatesCounter = Math.ceil(totalItemsToUpdate / limitItemsToUpdate); // If you need to count the remaining batch updates var restItemsToUpdate = 0; // Items to update after (see below) for (var i = 0; i < IDs.length; i++) { var oListItem = oList.getItemById(IDs[i]); /* Newly addedd get lookup id of items*/ //var lookupFieldValue = oListItem.get_item('LookUpColumn'); //var lookupId = lookupFieldValue.get_lookupId(); //console.log(LookUpColumnId); //alert(lookupFieldValue); //This works but when i set the lookupId above it doesn't i can;t even get the lookupId oListItem.set_item('LookUpID', 1); oListItem.update(); itemsToLoadForUpdate[i] = oListItem; clientContext.load(itemsToLoadForUpdate[i]); if (i && i % limitItemsToUpdate == 0) { console.log('Updating ' + limitItemsToUpdate + ' items...'); clientContext.executeQueryAsync(this.onUpdateSucceeded, this.onUpdateFailed); restItemsToUpdate = 0; } else { // Remaining items to update restItemsToUpdate = i % limitItemsToUpdate; } } if (restItemsToUpdate) { //console.log('Updating rest items...'); console.log('Updating ' + restItemsToUpdate + ' items...'); clientContext.executeQueryAsync(this.onUpdateSucceeded, this.onUpdateFailed); } } Thanks in Advance
Thanks in Advance
解决方案
No word from anyone from MS
这篇关于更新另一个id为查阅列的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文