在执行客户端上下文之前可以获取列表项的ID [英] Possible to get ID of List Item before executing client context

查看:68
本文介绍了在执行客户端上下文之前可以获取列表项的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CSOM在任务列表中创建项目. (循环)

I am using CSOM to create items inside a task list. (In a loop) 

在执行此操作时,我还想设置任务项的"Predecessor"字段(这是一个查找类型字段),并将其分配给任务列表中先前创建的项的ID.

While doing it I also want to set the 'Predecessor' field of the task Item (which is a lookup type field) and assign it to ID of previously created item in the task list.

由于我是在循环中生成任务项目,并且需要设置前置字段,因此我必须一一创建一个项目,以便一旦创建一个项目,我就可以获取它的ID并将其设置为下一个项目.它适合生成少量数字 项,但要创建1500多个项就变得很耗时.

Since I am generating task items in a loop and need to set the predecessor field, I have to do the one by one item creation so that once an item is created, I get the ID of it and set it as predecessor of next item. It works fine for generating small number of items but becomes bit time consuming when it comes to creation of say 1500+ items.

据我所知,批量插入项目将是理想的解决方案,但不能真正利用它,因为我需要先前创建的项目的ID才能设置下一个项目的Predecessor字段.

As far as I know, Batch insertion of items would be the ideal solution for this but cannot really leverage it because I need the ID of the previously created item in order to set the Predecessor field of next item.

有人可以推荐其他可能的最佳方法来执行此操作吗?还是可以使用指针呢?

Can anyone recommend other possible best way to execute this or pointers on is there any approach other than batch insertion can be leveraged here? 

Bhushan Gawale | RapidCircle

Bhushan Gawale | RapidCircle

推荐答案

请在下面的代码段供您参考:

Please code snippet below for your reference:

var parentID = 1;
for (int i = 0; i < 1500; i++)
{                   
	ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
	ListItem oListItem = oList.AddItem(listCreationInformation);
	oListItem["Title"] = "Test" + i;      
	FieldLookupValue lookup =new FieldLookupValue();
	lookup.LookupId = parentID;
	oListItem["ParentID"] = lookup;
	oListItem.Update();
	ctx.Load(oListItem);            
	ctx.ExecuteQuery();
	parentID = oListItem.Id;
}

或者,作为一种解决方法,我们可以创建两个列(currentId和parentId),然后将GUID值设置为这些列,然后根据两个列的关系更新查找字段.

Or as a workaround, we can create two columns(currentId and parentId) and then set the GUID value to the columns, then update the lookup field base on the tow columns relationship.

最好的问候,

丹尼斯


这篇关于在执行客户端上下文之前可以获取列表项的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆