8

Using CSOM is there anyway I can get the user that declared a document as record. I though I could use the last modified but it seems that when declaring a document as record last modified does not change.

  • It would be "Modified By" field which would hold the user's name. Additionally it's possible that you would need to dispose the SPWeb object you are referencing. This is a requirement to release a hold-status of the document which stays active after its declaration, thus actually finishing the update for the record's properties. Do you have it as part of your script? – moe Jul 17 '18 at 6:13
  • Yes I do have it as part of a different client object context (I am using CSOM), and counter intuitively the Modified By does not change after record declaration. – Luis Jul 18 '18 at 1:30
0

First, let's have look Microsoft.SharePoint.Client.RecordsRepository.Records DLL which does not contains any method to retrieve any property.

using System;

namespace Microsoft.SharePoint.Client.RecordsRepository
{
    [ScriptType("SP.RecordsRepository.Records", ServerTypeId = "{ea8e1356-5910-4e69-bc05-d0c30ed657fc}")]
    public static class Records
    {
        [Remote]
        public static void DeclareItemAsRecord(ClientRuntimeContext context, ListItem itemToDeclare);
        [Remote]
        public static void DeclareItemAsRecordWithDeclarationDate(ClientRuntimeContext context, ListItem itemToDeclare, DateTime declarationDate);
        [Remote]
        public static ClientResult<bool> IsRecord(ClientRuntimeContext context, ListItem item);
        [Remote]
        public static void UndeclareItemAsRecord(ClientRuntimeContext context, ListItem item);
    }
}

There is the just IsRecord method which has the boolean return type. Therefore not possible with CSOM using current SharePoint.Client DLL.

What possible solutions are,

  1. you can write a PowerShell script which code mentioned below:
$webApp = Get-SPWebApplication http://content.contoso.com

$siteColl = $webApp.Sites

foreach ($site in $siteColl)

{

       $webs = $site.AllWebs

       foreach ($web in $webs)

       {

             $lists = $web.Lists

             foreach ($list in $lists)

             {

                    if ($list.BaseTemplate -eq "DocumentLibrary")

                    {

                           if (($list.Title -ne "List Template Gallery") -and ($list.Title -ne "Reporting Templates") -and ($list.Title -ne "Form Templates") -and ($list.Title -ne "Customized Reports") -and ($list.Title -ne "Site Assets") -and ($list.Title -ne "Style Library"))

                           {           

                                 $auditQuery = New-Object -TypeName Microsoft.SharePoint.SPAuditQuery($site)   

                                 $items = $list.get_Items()

                                 foreach ($item in $items)

                                 {

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

                                        if ($IsRecord)

                                        {

                                               $auditQuery.RestrictToListItem($item)

                                               $auditResults = $site.Audit.GetEntries($auditQuery)

                                               foreach ($entry in $auditResults)

                                               {

                                                     $userId = $entry.UserId           

                                                     $userEntry = $web.AllUsers | Where {$_.ID -eq $userId}

                                                     $userLogin = $userEntry.LoginName

                                               }

                                               $declaredDate = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::RecordDeclarationDate($item)

                                               Write-Host $declaredDate $item.Name $userLogin

                                        }

                                 }

                           }

                    }

             }

       }

       $site.Dispose()

}

You can also execute PowerShell script from c#. Please! check the reference.

PowerShell script from C#

EDIT

  1. The possible scenario with CSOM.

Check below mention 2 references, first one is getting _vti_ItemDeclaredRecord and then you can retrieve audit log history and check on that timestamp who make that audit.

retrieve _vti_ItemDeclaredRecord

audit log using CSOM

code to retrieve _vti_ItemDeclaredRecord

    Records.IsRecord(file.Context, file.ListItemAllFields);

    string recordStatus = string.Empty;
    if (file.ListItemAllFields.Properties.FieldValues.ContainsKey("_vti_ItemHoldRecordStatus"))
    {
        switch (Convert.ToInt32(file.ListItemAllFields.Properties["_vti_ItemHoldRecordStatus"]))
        {
            case 0:
                recordStatus = "Normal Document";
                break;
            case 4353:
                recordStatus = "Hold";
                break;
            case 273:
                recordStatus = "Record";
                break;
            default:
                recordStatus = string.Empty;
                break;
        }
    }

    if (file.ListItemAllFields.Properties.FieldValues.ContainsKey("_vti_ItemDeclaredRecord"))
    {
        switch (Convert.ToDateTime(file.ListItemAllFields.Properties["_vti_ItemDeclaredRecord"]))
        {
            default:
                recordStatus = string.Empty;
                break;
        }
    }

Thanks

  • Thanks for the answer but this is not really an option as there is no CSOM only way to run that – Luis Jul 24 '18 at 7:40
0

There is no way to do this via CSOM, only option is to roll out a web service with SOM that we can then consume on the client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.