logo

Changing name of a business process task with a script. Naming templates.

You can add a template for naming process instances (to do that, click Instance names in the top menu of the process page in ELMA Designer). This way the instance name is formed automatically depending on the context variables and internal data of the current instance. Sometimes you need to name process tasks in the same way, but in ELMA Designer there is no possibility to attach a template for naming tasks. However, you can use scripts to reload the task creation method and create the task with the name specified in the script and not the one specified in the task's settings in the process graphic model. An example of such a script is given below.

//in the method parameters, instead of P_Process specify the class name of your process
//you can find it in the Settings tab of the process editing window
public override void OnTaskCreate(ITaskBase task, P_Process context)
{
  //select the required task by its name
  if (task.Subject == "Task1")
  {
    //give a new name
    task.Subject = "New name";
  }
}

"Task 1" is the name of the task specified in the user task activity in the process graphic model. Within the process, it must be unique for the process to work correctly. Instead of "New name" you can give any desired name or include a template using context variables as shown below:

//in the method parameters, instead of P_Process specify the class name of your process
//you can find it in the Settings window of the process editing window
public override void OnTaskCreate(ITaskBase task, P_Process context)
{
  //select the required task by its name
  if (task.Subject == "Task 1")
  {
    //give new name
    task.Subject = context.Name + " in process" + context.WorkflowInstance.Name;
  }
}

where context.Name is a string context variable that stores the task name, which can be specified by a user/initiator earlier in the process; context.WorkflowInstance.Name – is the name of the process instance.