Answer the question
In order to leave comments, you need to log in
How to make several checklists in one task?
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("tasks");
$arFields = Array(
"TITLE" => "Task title",
"DESCRIPTION" => "Task description",
"RESPONSIBLE_ID" => 721,
);
$obTask = new CTasks;
$ID = $obTask->Add($arFields);
$success = ($ID>0);
if($success)
{
echo "Ok";
$task = \CTaskItem::getInstance($ID, 721);
\CTaskCheckListItem::add($task, ['TITLE'=>'First item', 'SORT_INDEX'=>10, 'IS_COMPLETE'=>'N']);
}
else
{
if($e = $APPLICATION->GetException())
echo "Error: ".$e->GetString();
}?>
Answer the question
In order to leave comments, you need to log in
Change your checklist creation code, you can use the snippet:
use \Bitrix\Main,
\Bitrix\Tasks\CheckList\Task
;
Main\Loader::IncludeModule('tasks');
/**
* @var integer Идентификатор задачи
*/
$taskId = 6;
/**
* @var integer Идентификатор пользователя
*/
$userId = 1;
$result = Task\TaskCheckListFacade::add(
$taskId,
$userId,
[
'TITLE' => 'Test data',
'PARENT_ID' => 0,
'SORT_INDEX' => '10',
'IS_COMPLETE' => 'N',
'IS_IMPORTANT' => 'N',
'MEMBERS' => [],
'ATTACHMENTS' => [],
]
);
var_dump($result);
//First, we create the actual checklist (wrapper) with 'PARENT_ID' (so, we can create several such "wrappers") :
$result = TaskCheckListFacade::add(
$taskID,
$userID,
[
'TITLE' => $ checkList['TITLE'],
'PARENT_ID' => 0,
'SORT_INDEX' => $checkList['SORT_INDEX'],
'IS_COMPLETE' => $checkList['IS_COMPLETE'],
'IS_IMPORTANT' => $checkList['IS_IMPORTANT '],
]
);
//Then add items to it, specifying $result->getData()['ITEM']->getFields()['ID'] for them as 'PARENT_ID'
$item = TaskCheckListFacade::add(
$taskID,
$ userID,
[
'TITLE' => $listItem['TITLE'],
'PARENT_ID' => $result->getData()['ITEM']->getFields()['ID'],
'SORT_INDEX' => $ listItem['SORT_INDEX'],
'IS_COMPLETE' => $listItem['IS_COMPLETE'],
'IS_IMPORTANT' => $listItem['IS_IMPORTANT'],
]
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question