M
M
matveyboyko2018-12-11 12:46:12
1C-Bitrix
matveyboyko, 2018-12-11 12:46:12

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;
        }
    }

however, I did not quite understand what to substitute in the $disk_file_id variable.
Logically, this is the ID of the file in the system, but where will it come from if the file is only going to be downloaded?
Who will help you figure it out?
The downloaded file is not located on the local computer, but on the network at a specific path, there is only a link to it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-12-11
@matveyboyko

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 question

Ask a Question

731 491 924 answers to any question