Script for adding comments to a task

This article describes a method of adding comments to tasks automatically using scripts.
Let's take a look at two cases:

  • Adding a comment to any task
  • Adding a comment to a task of the current business process

Adding a comment to any task

Assume there is a task. In this example, a task is searched by a certain parameter (e.g. by ID).

Script without using PublicAPI.

For the script to work correctly, add namespaces:

using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Tasks.Managers;
 

Script text:

var instance = TaskBaseManager.Instance;
var task = instance.LoadOrNull(380); //Load a task by ID
instance.AddComment(task, "Comment"); //Add a comment to the task
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here
var task = PublicAPI.Portal.TaskBase.Task.LoadOrNull(380); // Load task by ID
PublicAPI.Portal.TaskBase.Task.AddComment(task, "Comment"); //Add a comment to the task


Adding a comment to a task of the current business process

Let's take as an example a business process (see figure). There is a gateway in the process: on the first path, a user task is executed (Task 2), the second path ends with a script. If the second path is completed before the Task 2, then the script adds a comment to the Task 2. The graphic model of the process:

(Script 1 adds a comment to the Task 2)

Script without using PublicAPI.

For the script to work correctly, add namespaces:

using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Tasks.Managers;
 

Script text:

var instance = TaskBaseManager.Instance;
var zdch = InterfaceActivator.Create<TaskBaseFilter>(); //create a filter on tasks
zdch.Subject = "Task 1"; // find a task by name (subject)
zdch.Statuses = new List<TaskBaseStatus>
    {
        TaskBaseStatus.NewOrder, 
        TaskBaseStatus.Read, 
        TaskBaseStatus.InProgress
    }; //check the task status
foreach (var task in instance.Find(zdch, null))
{
    instance.AddComment(task, "Comment"); //Add a comment to the task
}
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

 

Namespace:

using EleWise.ELMA.Tasks.Models;
 

Script text:

var nz = PublicAPI.Portal.TaskBase.Filter().Subject(context.X)  // find a task by name (subject)
                                    .Statuses(new List<TaskBaseStatus>
                                    {
                                        PublicAPI.Enums.Tasks.TaskBaseStatus.NewOrder,
                                        PublicAPI.Enums.Tasks.TaskBaseStatus.Read,
                                        PublicAPI.Enums.Tasks.TaskBaseStatus.InProgress
                                    }) //check the task status
                                    .Find();
foreach (var task in nz)
{
    PublicAPI.Portal.TaskBase.AddComment(task, context.Txt);
}
 

The subject parameter is written to the X context variable. Afte the execution of the script, a comment will be added to the specified task (Task 2). If more than one task with this name is found in the process, then a comment will be added to all of them. The comment displays the information, specified in the context variable (in this case, Txt).