Views: 10012
Last Modified: 16.09.2014

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)
 $dbUser = CUser::GetList(($by="id"), ($order="asc"), array("ID_EQUAL_EXACT"=>$userId), array("SELECT" => array("UF_*")));
 $arUser = $dbUser->GetNext();
 $i = 0;
 while ($i < $num)
  $arManagers = CIntranetUtils::GetDepartmentManager($arUser["UF_DEPARTMENT"], $arUser["ID"], true);
  foreach ($arManagers as $key => $value)
   $arUser = $value;
 $rootActivity = $this->GetRootActivity();
 $rootActivity->SetVariable("var5", "user_".$arUser["ID"]);

Courses developed by Bitrix24