If we are migrating data from other application or uploading data to record center through CSOM the data will be uploaded as record, but there is any issue if we want to update any meta data column, since record type is read only once we upload document we cant edit , to edit or to update any meta data column by default, to update the document properties, before uploading the document the autodeclartion of record settings need to change to manual declaration of record, after changing the settings document will be uploaded or migrate data in the form document, then after updating the metadata the document need to be converted as record
For Onprem site there is no client “RecordsRepository” dll exposed for converting document to record, so we need to go with powershell or server side, code let me explain the powershell script for converting document to record and changing back the settings to autodeclartion of record
Suppose if you have multiple sites or multiple list then provide Siteurl and ListName in the csv file and place it in common folder, while executing the provide the path of the csv file and I have logged only exception in the log file
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$File=REad-host -promp 'Enter the path for input CSV File'
$LogFilePath="D:recordlogrecordlog.log"
$tblData=Import-CSV $File
foreach($row in $tblData)
{
try
{
$mySite = $row.SiteURL
write-host $SiteURL
$Listname=$row.ListName
write-host $Listname
$spSite = Get-SPSite -Identity $mySite;
$spWeb = $spSite.OpenWeb();
Write-Host $spWeb.Url;
$list = $spWeb.GetList($spWeb.Url + "/"+$Listname);
Write-Host $list.Title
Write-Host $list.ItemCount;
foreach ($item in $list.Items)
{
try
{
$IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($Item)
$ItemType=$item.FileSystemObjectType
if($ItemType -eq "File")
{
if ($IsRecord -ne $true){
Write-Host "Declared for " $item.DisplayName
[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::DeclareItemAsRecord($Item)
}
}
}
catch{
$ErrorMessage = $_.Exception.Message
Add-Content -Path $LogFilePath -Value $ErrorMessage
Write-Host $ErrorMessage
$ErrorActionPreference="SilentlyContinue"
}
}
$list.RootFolder.Properties["ecm_AutoDeclareRecords"]="True"
$list.RootFolder.update()
}
catch{
$ErrorMessage = $_.Exception.Message
Add-Content -Path $LogFilePath -Value $ErrorMessage
Write-Host $ErrorMessage
$ErrorActionPreference="SilentlyContinue"
}
}
Read-Host "Process Completed"
Leave a comment