CBPDocument :: AddDocumentToHistory: Bitrix method

      
<?php 
//  CBPDocument :: AddDocumentToHistory()
//  /dist/bitrix/modules/bizproc/classes/general/document.php:185

    
public static function AddDocumentToHistory($parameterDocumentId$name$userId)
    {
        list(
$moduleId$entity$documentType) = CBPHelper::ParseDocumentId($parameterDocumentId);

        if (
strlen($moduleId) > 0)
            
CModule::IncludeModule($moduleId);

        if (!
class_exists($entity))
            return 
false;

        
$runtime CBPRuntime::GetRuntime();
        
$runtime->StartRuntime();

        
$historyService $runtime->GetService("HistoryService");
        
$documentService $runtime->GetService("DocumentService");

        
$userId intval($userId);

        
$historyIndex $historyService->AddHistory(
            array(
                
"DOCUMENT_ID" => $parameterDocumentId,
                
"NAME" => "New",
                
"DOCUMENT" => null,
                
"USER_ID" => $userId,
            )
        );

        
$arDocument $documentService->GetDocumentForHistory($parameterDocumentId$historyIndex);
        if (!
is_array($arDocument))
            return 
false;

        
$historyService->UpdateHistory(
            
$historyIndex,
            array(
                
"NAME" => $name,
                
"DOCUMENT" => $arDocument,
            )
        );

        return 
$historyIndex;
    }