Type parameters
Hierarchy
- BaseItem<ProcessTaskData>
- ItemRef<ProcessTaskItem<Context>>
-
ProcessTaskItemRef<Context>
- ProcessTaskItem
Properties
Readonly code
App code of the URL’s target (the app’s code).
Readonly data
Values of object’s fields.
Readonly fields
Description of the object’s fields.
Readonly id
ID of the URL’s target.
Readonly namespace
Namespace of the URL target (the code of the workspace that the app belongs to).
Methods
changeDueDate
-
Change the task due date.
Here is how to set a different due date for a task:
try { // Get the comment from the process context const comment = Context.data. comment; // Get the task ID from the process context const taskUUID = Context.data.taskid; let task = await System.processes._searchTasks(). where(x => x.__id.eq(taskUUID)).first(); // If the task does not exist, an error is displayed if (!task) { throw new Error('Задача не найдена'); } // Get the current date let newDueDate = new Datetime(); // Add one day newDueDate = newDueDate.addDate(0, 0, 1); await task.changeDueDate(newDueDate, comment); } catch (error) { // If the process has already finished, the exception can be processed }
Parameters
-
dueDate: TDatetime
New task due date.
-
Optional comment: undefined | string
Comment.
Returns Promise<void>
-
createReminder
-
Create a reminder.
Search for a task and create a reminder for it:
// Get the task object let task = await System.processes._searchTasks().where(x => x. __id.eq(taskUUID)).first(); // If the task object is not found, finish running the script if (!task) { return; } // Get the current user const user = await System.users.getCurrentUser(); // Get the current date and add 1 day // The time zone from the `System.timezones.current` fields is used let dateReminder = new Datetime(); dateReminder = dateReminder.add( new Duration(1, 'days')) // Create a reminder for the task for the next day await task.createReminder(dateReminder, user);
Parameters
-
date: TDatetime
Reminder date.
-
user: UserItemRef
User who will receive the reminder.
Returns Promise<ReminderItem>
Reminder.
-
fetch
-
Request complete data of a reference object.
Returns Promise<ProcessTaskItem<Context>>
getExits
-
Get possible task transitions.
Here is how to search for a task and finish it:
try { // Get the task object let task = await System.processes._searchTasks(). where(x => x.__id.eq(taskUUID)).first(); // If the task object is not found, the execution of the script finishes if (!task) { return; } // Get task transitions const exits = await task.getExits(); // Finish the task // Pass the transition’s ID and the form’s data await task.submitTask(exits[0].id, {comment: 'Task completed'}); } catch (e) { // If the process is already finished, the exception is processed }
Returns Promise<TaskItemExit[]>
getPerformers
-
The method returns the list of task executors.
const instance = await task.getPerformers();
Returns Promise<UserItem[]>
Users who are executors of the task.
getProcessInstance
-
The method returns a process object.
const instance = await task.getProcessInstance();
Returns Promise<ProcessInstanceItem<Context>>
The process that the task is started from.
normalize
-
Delete duplicate data in arrays.
The method deletes duplicates in fields that store arrays of links to system objects (users, files, app items, or documents). For example, you can call this method after bulk editing data within an object.
const app1 = await Context.data.app1.fetch(); const app2 = await Context.data.app2 .fetch(); app1.data.executors.push(app2.data.executors); app1.normalize(); // Now we need to go over the elements in the new array app1.data.executors .forEach( ... );
Returns void
reassign
-
Reassign a task to one or more new executors.
The reason for reassigning the task is written to the task’s activity stream. Review and approval tasks as well as system tasks are assigned to the first user in the list of new executors. If the corresponding process instance or the task is already finished, the method throws an exception.
In the example, we reassign a task using its ID from the context to one new executor.async function reassign(): Promise<void> { // Getting the task ID for reassigning from the process context const taskID = Context.data.TaskForReassignUUID; // Searching for the task const task = await Application.processes._searchTasks().where(x => x. __id.eq(taskID)).first(); // Getting the user from the context const user = Context.data.NewPerformer; const comment = 'Replacing the executor'; await task.reassign(user, comment); }
In the second example, we reassign a task using its ID from the context to users from a group.
async function reassignMany(): Promise<void> { // Getting the task ID for reassigning from the process context const taskID = Context.data.TaskForReassignUUID; // Searching for the task const task = await Application.processes._searchTasks().where(x => x. __id.eq(taskID)).first(); // Getting the user group ID from the context const userGroupID = Context.data.groupUUID; // Searching for the user group const userGroup = await System.userGroups.search().where(x => x.__id.eq(userGroupID)).first(); const newPerformers = <UserItemRef[] >await userGroup.users(); const comment = 'Reassigning to several executors'; await task.reassign(newPerformers, comment); }
Parameters
-
user: UserItemRef | UserItemRef[]
A link to a user or an array of links to users.
-
Optional comment: undefined | string
Reason for reassigning the task. You can pass an empty string.
Returns Promise<void>
-
submitTask
-
The method finishes a task.
Here is how to search for a task and finish it:
try { // Get the task object let task = await System.processes._searchTasks(). where(x => x.__id.eq(taskUUID)).first(); // Get task transitions const exits = await task.getExits(); // Pass the transition’s ID and the form’s data await task.submitTask(exits[0].id, {comment: 'Task completed'}); } catch (e) { // If the process is already finished, the exception is processed }
Parameters
-
exitID: string
-
Optional data: Context
Returns Promise<void>
-
Process task object