CBPDocument::StartWorkflow: Bitrix method

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

    
public static function StartWorkflow($workflowTemplateId$documentId$parameters, &$errors$parentWorkflow null)
    {
        
$errors = [];
        
$runtime CBPRuntime::GetRuntime();

        if (!
is_array($parameters))
        {
            
$parameters = [$parameters];
        }

        if (!
array_key_exists(static::PARAM_TAGRET_USER$parameters))
        {
            
$parameters[static::PARAM_TAGRET_USER] = is_object($GLOBALS["USER"]) ? "user_".intval($GLOBALS["USER"]->GetID()) : null;
        }

        if (!isset(
$parameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS]))
        {
            
$parameters[static::PARAM_MODIFIED_DOCUMENT_FIELDS] = false;
        }

        if (!isset(
$parameters[static::PARAM_DOCUMENT_EVENT_TYPE]))
        {
            
$parameters[static::PARAM_DOCUMENT_EVENT_TYPE] = CBPDocumentEventType::None;
        }

        try
        {
            
$wi $runtime->CreateWorkflow($workflowTemplateId$documentId$parameters$parentWorkflow);
            
$wi->Start();
            return 
$wi->GetInstanceId();
        }
        catch (
Exception $e)
        {
            
$errors[] = array(
                
"code" => $e->getCode(),
                
"message" => $e->getMessage(),
                
"file" => $e->getFile()." [".$e->getLine()."]"
            
);
        }

        return 
null;
    }