Documentation

Add

int
CTasks::Add(
 array arFields,
 array arParams = array()
);

Adds a new task.

Method parameters

Parameter Description Available from version
arFields Array("field"=>"value", ...). Contains values of all task fields. The fields:
  • TITLE - task name (can be searched by the template: [%_] ;) ;
  • DESCRIPTION - task description;
  • DEADLINE - deadline;
  • START_DATE_PLAN - planned start date;
  • END_DATE_PLAN - planned completion date;
  • PRIORITY - defines priority. The field can have the following values: [1] - Standard, [2] - High;
  • ACCOMPLICES - participants (user IDs);
  • AUDITORS - observers (user IDs);
  • TAGS - tags;
  • ALLOW_CHANGE_DEADLINE - flag "Allow for responsible user to change deadline";
  • TASK_CONTROL - flag "Accept after task is completed";
  • PARENT_ID - parent task ID;
  • DEPENDS_ON - previous task ID;
  • GROUP_ID - workgroup ID;
  • RESPONSIBLE_ID - responsible user ID;
  • TIME_ESTIMATE - planned worktime estimate;
  • CREATED_BY - task creator ID;
  • DECLINE_REASON - reason for task to be declined;
  • STATUS - meta-status of task;
  • DURATION_PLAN - planned duration in hours or days;
  • DURATION_TYPE - type of unit of measurement in the planned duration: days или hours;
  • MARK - evaluation for a task (possible values: P (positive) and N (negative));
  • ALLOW_TIME_TRACKING - flag to enable time tracking for a task;
  • ADD_IN_REPORT - flag to include task into the effectiveness report;
  • FORUM_ID - forum ID, where task comments are stored;
  • FORUM_TOPIC_ID - forum topic ID, where task comments are stored;
  • SITE_ID - site ID. By default, site ID, where the task is created is recorded into this field;
  • MATCH_WORK_TIME - flag that shows that completion dates and the deadline shall always be specified within worktime;
arParams Array of additional parameters. Optional.

Returned value

This method returns the added task ID, if the adding was successful. If an error occurs, the method will return false, and exceptions will contain errors. 

Examples

<?
if (CModule::IncludeModule("tasks"))
{
	$arFields = Array(
		"TITLE" => "Task title",
		"DESCRIPTION" => "Task description",
		"RESPONSIBLE_ID" => 2,
		"GROUP_ID" => 3
	);
	$obTask = new CTasks;
	$ID = $obTask->Add($arFields);
	$success = ($ID>0);
	if($success)
	{
		echo "Ok!";
	}
	else
	{
		if($e = $APPLICATION->GetException())
			echo "Error: ".$e->GetString();  
	}
}?>

//Creating task with high priority
{
	$arFields = Array("TITLE" => "High priority task",
		"DESCRIPTION" => "Task description",
		"RESPONSIBLE_ID" => 3,
		"CREATED_BY" => 1,
		"PRIORITY" => 2 // 2 has high priority
	);
	$obTask = new CTasks;
	$obTask->Add($arFields);
}


© «Bitrix24», 2001-2024