S
S
Sergey Zaigraev2017-12-23 10:38:21
Bitrix24
Sergey Zaigraev, 2017-12-23 10:38:21

Bitrix 24. Why is the file not attached to the task?

Good day.
I'm trying to create a task using the API and attach a file to it, I do it like this:

$arFields = Array (
     "TITLE" => "Title",
      "DESCRIPTION" => "Description",
      "RESPONSIBLE_ID" => "2",
      "PRIORITY"=> "1",
      "CREATED_BY"=>23,
      "GROUP_ID"=>14,
      "DEADLINE"=> $date,
     "UF_CRM_TASK"=>array(
     "C_".$user_id,
     "CO_".$arComp["ID"]
   )
);
$obTask = new CTasks;
$task_id = $obTask->Add($arFields); // Задача успешно создается

I try to attach a file I add a file to the user's file library and after:
$arFile = $_FILES["file"];
if($ElemID) {

     try {
     
      $oTaskItem = new CTaskItem($task_id, ID_USER_TICKETS);
      $rs = $oTaskItem->Update(
                      array(
                          "UF_TASK_WEBDAV_FILES" => array($ElemID)
                       ),        
                    array(
                          "USER_ID" => ID_USER_TICKETS,
                           "CHECK_RIGHTS_ON_FILES" => false
                     )
          );
  }
       catch (TasksException $e) {

   pr($e,true);
  return;
 }
   }

I create a task and add a file under an unauthorized user
TasksException Object
(
    [data:protected] => Array
        (
        )

    [additional:protected] => Array
        (
            [CODE] => 1048584
        )

    [errors:protected] => 
    [messageOrigin:protected] => a:1:{i:0;a:2:{s:2:"id";s:16:"WD_ERR_IBLOCK404";s:4:"text";s:35:"Инфоблок не найден.";}}
    [message:protected] => a:1:{i:0;a:2:{s:2:"id";s:16:"WD_ERR_IBLOCK404";s:4:"text";s:35:"Инфоблок не найден.";}}
    [string:Exception:private] => 
    [code:protected] => 1048584
    [file:protected] => /bitrix/modules/tasks/classes/general/taskitem.php
    [line:protected] => 2550
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /bitrix/modules/tasks/classes/general/taskitem.php
                    [line] => 2249
                    [function] => throwExceptionVerbose
                    [class] => CTaskItem
                    [type] => ::
                    [args] => Array
                        (
                            [0] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => WD_ERR_IBLOCK404
                                            [text] => Инфоблок не найден.
                                        )

                                )

                        )

                )

            [1] => Array
                (
                    [file] => /bitrix/modules/tasks/classes/general/taskitem.php
                    [line] => 1652
                    [function] => proceedAction
                    [class] => CTaskItem
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 9
                            [1] => Array
                                (
                                    [FIELDS] => Array
                                        (
                                            [UF_TASK_WEBDAV_FILES] => Array
                                                (
                                                    [0] => 16939
                                                )

                                        )

                                    [PARAMETERS] => Array
                                        (
                                            [USER_ID] => 23
                                            [CHECK_RIGHTS_ON_FILES] => 
                                        )

                                )

                        )

                )

            [2] => Array
                (
                    [file] => /help/index.php
                    [line] => 202
                    [function] => update
                    [class] => CTaskItem
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                    [UF_TASK_WEBDAV_FILES] => Array
                                        (
                                            [0] => 16939
                                        )

                                )

                            [1] => Array
                                (
                                    [USER_ID] => 23
                                    [CHECK_RIGHTS_ON_FILES] => 
                                )

                        )

                )

        )

    [previous:Exception:private] => 
)

At the same time, if you add a file by logging in to the portal, there are no problems, the file is added via the API normally.
What can I be missing?
Has anyone solved similar problems?
I will be glad to any advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Zaigraev, 2017-12-23
@SergeyZaigraev

Solved the problem in the following way:

global $USER;
$USER->Authorize(ID_USER_TICKETS);

if($ElemID){

   try{

      $oTaskItem = new CTaskItem($task_id, ID_USER_TICKETS);
      $rs = $oTaskItem->Update(
         array(
            "UF_TASK_WEBDAV_FILES" => array($ElemID)
         ),
         array(
            "USER_ID" => ID_USER_TICKETS,
            "CHECK_RIGHTS_ON_FILES" => false
         )
      );
   }
   catch (TasksException $e) {
      pr($e,true);
      return;
   }
}
$USER->Logout();

because under an authorized user there are no problems with attaching a file, in fact, I decided to authorize my user before adding it and log out after adding it, I don’t know how correct this approach is, but it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question