Template :: addBizprocTemplate: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Engine\Template :: addBizprocTemplate()
//  /dist/bitrix/modules/bizproc/lib/automation/engine/template.php:295

    
protected function addBizprocTemplate($userId)
    {
        
$userId = (int)$userId;
        
$documentType $this->getDocumentType();

        
$raw $this->template;
        
$raw['DOCUMENT_TYPE'] = $documentType;
        
$raw['NAME'] = $this->makeTemplateName();
        
$raw['USER_ID'] = $userId;
        
$raw['MODIFIER_USER'] = new \CBPWorkflowTemplateUser($userId);

        
$result = new Result();
        try
        {
            
$raw['ID'] = \CBPWorkflowTemplateLoader::add($raw$userId === 1);
            
$result->setData(array('ID' => $raw['ID']));

            
$raw['MODULE_ID'] = $documentType[0];
            
$raw['ENTITY'] = $documentType[1];
            
$raw['DOCUMENT_TYPE'] = $documentType[2];
            
$raw['PARAMETERS'] = [];
            
$raw['CONSTANTS'] = [];
            
$this->template $raw;
        }
        catch (\
Exception $e)
        {
            
$result->addError(new Error($e->getMessage()));
        }

        return 
$result;
    }