【问题标题】:Exception CICONotCheckedOut when removing items from LookupTable using Project Server CSOM API使用 Project Server CSOM API 从 LookupTable 中删除项目时出现异常 CICONotCheckedOut
【发布时间】:2015-01-08 22:21:22
【问题描述】:

我有一个 Project Online 解决方案,需要从 LookupTable (Microsoft.ProjectServer.Client.LookupTable) 中删除项目,因为我需要在添加新项目之前清除它。这样做的主要用途是在我创建项目时进行单元测试,然后在测试完成后清除所有内容。

每次运行此程序时,我都会收到代码为 0x80131500 (-2146233088) 的异常,并显示错误消息“PJClientCallableException: CICONotCheckedOut\r\nCICONotCheckedOut”,执行 ExecuteQuery 时会引发异常。

我可以在不检查任何内容的情况下添加新项目并将现有项目更改到 LookupTable。并且 LookupTable 上没有 CheckOut 方法。所以我不知道该怎么办......

Project Online 的唯一选项是使用 Project Server CSOM API,不能使用 PSI。

例外:

Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at <mynamespace>.LookupTableHelper.DeleteAllItems(Guid tableGuid)

代码:

// Create password
SecureString securePassword = new SecureString();
foreach (char c in "qwerty") securePassword.AppendChar(c);
Microsoft.SharePoint.Client.SharePointOnlineCredentials cred = new Microsoft.SharePoint.Client.SharePointOnlineCredentials("a@b.com", securePassword);

// Connect
ProjectContext context = new ProjectContext(urlToProjectOnlineWeb);
context.Credentials = cred;

// Get entries in lookup table
LookupTable lookupTable = context.LookupTables.GetByGuid(tableGuid);
context.Load(lookupTable.Entries);
context.ExecuteQuery();

if (lookupTable.Entries.Count > 0)
{
    // If there are items in the collection, then remove the first item
    LookupEntry e = lookupTable.Entries[0];
    lookupTable.Entries.Remove(e);
}

// Upload the change to cloud
context.LookupTables.Update();
context.ExecuteQuery(); // Always throw PJClientCallableException: CICONotCheckedOut\r\nCICONotCheckedOut

解决方案(至少是迄今为止最好的)是首先执行添加以签出表格,然后删除所有现有项目。这给我留下了一件无法移除的物品。但总比不能删除任何东西要好...谢谢 Jogeukens!

// Create password
SecureString securePassword = new SecureString();
foreach (char c in Configuration.GetConfig().PASSWORD.ToCharArray()) securePassword.AppendChar(c);
Microsoft.SharePoint.Client.SharePointOnlineCredentials cred = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(Configuration.GetConfig().USERNAME, securePassword);

// Connect
ProjectContext context = new ProjectContext(Configuration.GetConfig().PPM_URL);
context.Credentials = cred;

// Get entries in lookup table
LookupTable lookupTable = context.LookupTables.GetByGuid(tableGuid);
context.Load(lookupTable.Entries);
context.ExecuteQuery();

LookupEntryCreationInformation newEntry = new LookupEntryCreationInformation();
newEntry.Id = Guid.NewGuid();
newEntry.Value = new LookupEntryValue();
newEntry.Value.TextValue = "The one that cannot be removed...";
lookupTable.Entries.Add(newEntry);

while(lookupTable.Entries.Count > 1)
{
    // If there are items in the collection, then remove the first item
    LookupEntry e = lookupTable.Entries[0];
    lookupTable.Entries.Remove(e);
}

// Upload the change to cloud
context.LookupTables.Update();
context.ExecuteQuery();

【问题讨论】:

    标签: csom project-server ms-project-server-2013


    【解决方案1】:

    您可以使用 PSI 代码删除查找条目。 lutDs.LookupTableTrees.Rows[i].Delete();

                    lookupTableWS.CheckOutLookupTables(lutList);
                    bool validateOnly = false;
                    lookupTableWS.UpdateLookupTables(lutDs, validateOnly, autoCheckOut, 1033);
                    bool forceCheckIn = false;
                    lookupTableWS.CheckInLookupTables(lutList, forceCheckIn);
    

    供参考Delete Existing Lookup Entry from Lookup Table using PSI

    【讨论】:

      【解决方案2】:

      另一种解决方案是从 PWA 打开查找表,然后运行代码。我这样做是为了对查找表中的值进行巨大更改。在这种情况下不需要添加。

      【讨论】:

      • 在响应时考虑添加一些代码/查询示例
      【解决方案3】:

      只是想补充一点,我遇到了同样的问题,并确认如果没有使用相同的查询添加某些内容,CSOM 将无法删除项目。即使在提交查询之前添加和删除相同的项目也会引发错误。查询必须最终添加一个项目才能使删除工作。

      但是 PSI 工作得很好。不确定 Mattias 是否意味着由于项目要求不允许他使用 PSI,但我在我的 Project Online 开发中使用 PSI 来补充 CSOM,因为 CSOM 仍然有很多缺点。

      【讨论】:

        【解决方案4】:

        我没有足够的声誉来发表评论,但你可能会从中得到一些帮助:

        我遇到了同样的问题,最后我能够通过确保每次删除都发生在与添加相同的更新中来解决它。 显然“Lookuptable.entries.add()”会自动检查查找表,而 Lookuptable.entries.Remove() 没有。

        因此,通过在一次更新中同时获取它们,您可以使用添加中的结帐来删除其他条目。

        当然,如果您不需要添加新条目,这将不起作用。如果您发现任何其他更可靠的解决方案,请将它们添加为答案。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-08-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多