Answer the question
In order to leave comments, you need to log in
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); // Задача успешно создается
$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;
}
}
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] =>
)
Answer the question
In order to leave comments, you need to log in
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();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question