0

We have had a PowerShell script scheduled and executing successfully for the past 3-4 months (In both Test and Prod). The purpose of the script is to update document properties in SharePoint when certain triggers are fired from external systems. Without getting into too much detail, below is the code that has been used to update item properties for a document that has been declared a record:

$recordsmanagement=[Microsoft.Office.RecordsManagement.RecordsRepository.Records]
$recordsmanagement::UndeclareItemAsRecord($item)
$item = $list.GetItemById($item.id)     
$item.File.CheckOut()
$item[$sSpFieldName]=$sDbValue
$item.Update()                                          
$item = $list.GetItemById($item.id)                                 
$item.File.CheckIn("")                          
$recordsmanagement::DeclareItemAsRecord($item)

This code has worked hundreds of times without a problem. For some reason, this code started bombing a week ago on the last line (when re-declaring as a record):

System.Management.Automation.MethodInvocationException: Exception calling "DeclareItemAsRecord" with "1" argument(s): "The file /lib/folder/file.pdf has been modified by SHAREPOINT\system on 10 Oct 2012 00:00:47 -0500."

The other weird part is that this is only happening in Prod. The Test environment seems to execute just fine. I haven't tried a fix for production yet, but I'm pretty sure I can just get the $item object again using GetItemById (after the CheckIn). I'm a little hesitant to do this just yet as I wanted to get some other people's perspective first.

Does anyone have any input on this? Thanks in advance.

4

1 回答 1

0

我认为最好的选择是按照您所说的在办理登机手续后再次获得该物品。

错误消息正是表明了这一点。您正在尝试对已修改的 SPListItem 执行操作。因此,在将其声明为记录之前,请使用 GetItemById 再次拉取它。

为什么它只发生在某些记录和某些环境中,我不确定。我猜Sharepoint有点喜怒无常。

我也会尝试的事情:

  • 签入时检查是否有任何工作流程对该项目进行一些工作
  • 如果符合您的要求,请尝试使用 SystemUpdate() 而不是 Update()

祝你好运

于 2012-10-15T14:14:14.900 回答