我设法通过c#在苦苦挣扎的在线中在SharePoint中添加任务(也许是由于缺少更好的搜索词):
如何将子任务添加到现有任务/如何将子任务分配给父任务?
答案似乎位于ParentID字段中,该字段显示通过Sharepoint任务列表手动在线输入时与另一个任务的连接。
在这种情况下,该字段为子节点显示以下条目:
let a = [{
farmer_revenue_id: 63,
farmer_id: 518,
activity_id: 0,
revenue_type: 1,
value_date: '2018-07-01',
amount: '558.00',
remarks: '',
capture_date: '2018-07-17'
}];
let b = [{
revenue_type_id: 1,
name: 'Sale'
}];
a = a.reduce((reduced, aItem) => {
const aItemClone = {...aItem};
const foundB = b.find((bItem) =>
bItem.revenue_type_id === aItemClone.revenue_type
) || null;
if (foundB !== null)
aItemClone.revenue_type_name = foundB.name;
delete aItemClone.revenue_type;
reduced.push(aItemClone);
return reduced;
}, []);
console.log(a);
我有一个父节点的ID(例如60),并且我从Internet上的研究中了解到TypeID是可以修复的(希望我的研究是正确的)。 我认为关键可能是使用KeyValuePair并将结果分配给ParentID。这是我的代码:
- [12] {[ParentID, Microsoft.SharePoint.Client.FieldLookupValue]} System.Collections.Generic.KeyValuePair<string, object>
Key "ParentID" string
- Value {Microsoft.SharePoint.Client.FieldLookupValue} object {Microsoft.SharePoint.Client.FieldLookupValue}
LookupId 60 int
LookupValue "60" string
TypeId "{f1d34cc0-9b50-4a78-be78-d5facfcccfb7}" string
我得到或更准确的抛出异常的结果是{“ Unknown Error”}。
我现在不知道该去哪里,或者下一步该怎么做,你有什么主意吗? KeyValuePair的想法是否正确?
答案 0 :(得分:0)
示例代码供您参考。
using (var clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = new SharePointOnlineCredentials(login, securePassword);
List myList = clientContext.Web.Lists.GetByTitle("MyTask");
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
ListItem newItem = myList.AddItem(listItemCreationInformation);
newItem["Title"] = "subTask";
newItem["Body"] = "body";
FieldLookupValue lookupParent = new FieldLookupValue();
//hardcode for test purpose
lookupParent.LookupId = 3;
newItem["ParentID"] = lookupParent;
newItem.Update();
clientContext.ExecuteQuery();
}