Type parameters

Hierarchy

Properties

Readonly code

code: string

App code of the URL’s target (the app’s code).

Readonly data

data: Based<Partial<ProcessTaskData>>

Values of object’s fields.

Readonly fields

fields: Readonly<object>

Description of the object’s fields.

Readonly id

id: string

ID of the URL’s target.

Readonly namespace

namespace: string

Namespace of the URL target (the code of the workspace that the app belongs to).

Methods

changeDueDate

  • changeDueDate(dueDate: TDatetime, comment?: undefined | string): Promise<void>
  • 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.

    Example of searching for a task and creating a reminder for it:

    // Get the tast object 
    let task = await System.processes. _searchTasks().where(x => x.__id.eq(taskUUID)).first(); 
    // If the task  object is not found, stop the script execution 
    if (!task) { 
     return; 
    } 
    //  Get the current user 
    const user = await System.users.getCurrentUser(); 
    //  Get the current date and add one day 
    // The time zone is taken from the  field `System.timezones.current` 
    let dateReminder = new Datetime();  
    dateReminder = dateReminder.add(new Duration(1, 'days')) 
    // Create a  reminder for the task on the next day 
    await task.createReminder( dateReminder, user); 
    

    Parameters

    Returns Promise<ReminderItem>

    Reminder.

fetch

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

  • normalize(): void
  • 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

  • submitTask(exitID: string, data?: Context): Promise<void>
  • 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>