Answer the question
In order to leave comments, you need to log in
How to add a file to a task in Bitrix?
Hey!
Found the following code for my purpose:
if (CModule::IncludeModule('disk') && CModule::IncludeModule('tasks')){
$oTask = new CTaskItem($task_id, $user_id);
$arFields = array(
"UF_TASK_WEBDAV_FILES" => array("n".$disk_file_id)
);
try
{
if ( ! $oTask->update($arFields) )
throw new TasksException();
}
catch (TasksException $e)
{
print_r($e);
return;
}
}
Answer the question
In order to leave comments, you need to log in
The file must be downloaded first.
There is an example in the documentation: https://dev.1c-bitrix.ru/api_help/tasks/classes/ct...
CModule::IncludeModule('tasks');
$storage = Bitrix\Disk\Driver::getInstance()->getStorageByUserId($USER_ID);
$folder = $storage->getFolderForUploadedFiles();
$arFile = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/upload/wlog.txt");
$file = $folder->uploadFile($arFile, array(
'NAME' => $arFile["name"],
'CREATED_BY' => $USER_ID
), array(), true);
$FILE_ID = $file->getId();
$oTaskItem = new CTaskItem($taskId, $userId);
$rs = $oTaskItem->Update(array("UF_TASK_WEBDAV_FILES" => Array("n$FILE_ID")));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question