Documentation

update

Description and parameters

bool
CTaskItem::Update(
 array arFields
);

Non-static method that updates parameters for the task with ID.

Method parameters

Parameter Description Available from version
arFields

Returned value

When an error occurs, exceptions will contain the error text.

Examples of use

// changing user that is responsible for the task 

CModule::IncludeModule('tasks');

global $USER;

$userId = $USER->GetID();
$taskId = 85;

$oTaskItem = new CTaskItem($taskId, $userId);

try
{
   $rs = $oTaskItem->Update(array("RESPONSIBLE_ID" => 480));
}
catch(Exception $e)
{
   print('Error');
}



// attaching file to the task

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")));

Adding file to task with already added files. The example above re-writes the added file.

$taskId = 183; //task id
$userId = 1; // user id, that updates the task
$newFileId = 324; //new file ID from таблицы b_disk_object
$task = new CTaskItem($taskId, $userId);
$taskData = $task->getData(false);

$task->update(['UF_TASK_WEBDAV_FILES' => array_merge($taskData['UF_TASK_WEBDAV_FILES'], ["n{$newFileId}"])]); 


© «Bitrix24», 2001-2024
Up