Views: 966 (Data available since 06.02.2017)

In order to find out who the manager of the document initiator is, who is using the activity PHP code (i.e., without using the userís choice activity), you can use the code provided below.

In this code, the variable $num shows the managerís level (1 Ė direct supervisor, 2 Ė managerís manager,..). Managerís ID in a BP format (i.e. of the user_X type) is recorded into a variable with the name var5. This variable must be created in BP parameters and must have a linked-to-user type.

$num = 1;
$userId = substr("{=Document:CREATED_BY}", 5);
$userId = intval($userId);
if ($userId > 0)
{
 CModule::IncludeModule("intranet");
 $dbUser = CUser::GetList(($by="id"), ($order="asc"), array("ID_EQUAL_EXACT"=>$userId), array("SELECT" => array("UF_*")));
 $arUser = $dbUser->GetNext();
 $i = 0;
 while ($i < $num)
 {
  $i++;
  $arManagers = CIntranetUtils::GetDepartmentManager($arUser["UF_DEPARTMENT"], $arUser["ID"], true);
  foreach ($arManagers as $key => $value)
  {
   $arUser = $value;
   break;
  }
 }
 $rootActivity = $this->GetRootActivity();
 $rootActivity->SetVariable("var5", "user_".$arUser["ID"]);


Courses developed by «Bitrix», Inc.