Question

I am trying to undeclare a record but it won't just work for some documents while it works for most of the document. It will say this item cannot be undeclared as a record because it is checked out. When I try to discard the checked out, it says the item cannot be updated because it is locked as read only

I tried manually and even using PowerShell to discard the checked out/checkin the document/undeclare the record, but nothing worked.

I searched all over the internet and all the solutions provided are not working in this case. I tried even these: http://weblogs.asp.net/peterbrunone/read-only-lock-on-a-sharepoint-site-collection-or-why-can-t-i-edit-anymore

http://www.codeproject.com/Articles/93965/Force-SharePoint-Document-Unlocked-Checked-In

Nothing helped me undeclare the document. Please help me undeclare the records. What can be the reason? Why this is happening with only few documents and not all?

Was it helpful?

Solution 2

$checkout = {
param(
[Microsoft.SharePoint.SPListItem]$a
)
$a.File.UndoCheckOut()
$a.File.Update()
$a.SystemUpdate($true)
}

[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::bypasslocks($item, $checkout)

[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($item)

This code helped me bypass the lock and undeclare it :)

OTHER TIPS

I had the same problem. It occured, when a user downloaded a Office-Document in Record-State, changed it and uploaded it again. I guess the reason is that, because some of the metadata fields are stored in the properties of the office document itself, while properties are not. And if the document is uploaded again, the metadatafields are imported again, but the properties set are missing. And the "Records"-function relies on a summary of metadatafields and properties. So Sharepoint believes the document is a record (because of the metada-fields), but cannot unlock it because of the missing properties.

However: I made some code, which was able to correct this

                if (Records.IsRecord(currentItem))
            {
                //necessary, because obviously the replacement file has been downloaded from sharepoint in Record-State

                var siteId = currentItem.Web.Site.ID;
                var webId = currentItem.Web.ID;
                var url = currentItem.File.ServerRelativeUrl;
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (var site = new SPSite(siteId))
                    using (var web = site.OpenWeb(webId))
                    {
                        var elevatedItem = web.GetListItem(url);
                        Records.BypassLocks(elevatedItem, delegate(SPListItem item)
                        {
                            if (item.Fields.Contains(Microsoft.SharePoint.Publishing.FieldId.HoldRecordStatus))
                            {
                                item[Microsoft.SharePoint.Publishing.FieldId.DeclaredRecord] = null;
                                item[Microsoft.SharePoint.Publishing.FieldId.HoldRecordStatus] = null;
                                if (item.Fields.Contains(Microsoft.SharePoint.Publishing.FieldId.IsLocked))
                                    item[Microsoft.SharePoint.Publishing.FieldId.IsLocked] = null;
                                item.Properties["ecm_ItemLockHolders"] = null;
                                item[Microsoft.SharePoint.Publishing.FieldId.IconOverlay] = null;
                                item.SystemUpdate();
                            }
                        });
                    }
                });
                currentItem = currentItem.Web.GetListItem(currentItem.File.ServerRelativeUrl);
            }

In my case that code is executed when a new document is uploaed. It checks if it is in Record-State, (which can´t really be for new Document). You could modify it to your needs. In Fact the code bypasses the lock (because unlock does not work) and cleans the necessary metadafields by itself (in fact removing a lock manually).

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top