Skip to main content
Version: 8.0

Implement a custom user task

Level: intermediate
Example

Implement a custom User task of sum numbers user task. The task must calculate the sum of two integers that are specified in the task parameters. Display the calculation result on an auto-generated business process page.

1. Create a user task schema

  1. Go to the Configuration section and select a user-made package to add the schema.

  2. Click AddUser task on the section list toolbar.

  3. Fill out the schema properties in the User Task Designer.

    • Set Code to "UsrSumNumbersProcessUserTask."
    • Set Title to "User task of sum numbers."

    Click Apply to apply the properties.

  4. Add a user task parameter that contains the first integer.

    1. Click in the properties area of the Parameters node’s context menu.

    2. Fill out the parameter properties in the User Task Designer.

      • Set Code to "FirstNumber."
      • Set Title to "First number."
      • Set Type to "Integer."
      • Set the Serializable checkbox.
    3. Click Create to add a parameter.

  5. Add user task parameters that contain the following in a similar way:

    • second integer
    • integer sum

    View the properties of the parameters to add in the table below.

    Parameter property values

    Parameter

    Property

    Property value

    Parameter that contains the second integer

    Code

    "SecondNumber"

    Title

    "Second number"

    Type

    Select "Integer"

    Serializable checkbox

    Set

    Parameter that contains the integer sum

    Code

    "SumNumbers"

    Title

    "Sum of numbers"

    Type

    Select "Integer"

    Serializable checkbox

    Set

  6. Implement the logic to add integers. To do this, implement the InternalExecute() method of the user task schema’s automatically generated source code.

    InternalExecute() method
    protected override bool InternalExecute(ProcessExecutingContext context) {
    /* Execute operations with task parameters. */
    SumNumbers = FirstNumber + SecondNumber;
    /* Specify that the task was completed successfully. */
    return true;
    }

  7. Click Publish on the User Task Designer’s toolbar to apply the changes to the database level.

2. Implement a business process

  1. Go to the Configuration section and select a user-made package to add the schema.

  2. Click AddBusiness process on the section list toolbar.

  3. Fill out the properties of the business process:

    • Set the Title property in the element setup area to "Sum of numbers process."
    • Set the Code property on the Settings tab of the element setup area to "UsrProcessSumNumbers."
  4. Implement the business process.

    View the business process in the figure below.

    1. Add the user task.

      1. Click System actions in the Designer’s element area and place a User task element between the Simple start event and Terminate end event in the Process Designer’s working area.

      2. Fill out the user task properties.

        • Select "User task of sum numbers" in the Which user task to perform? property.

        • Fill out the user task parameters.

          • Set First number to "12."
          • Set Second number to "23."
    2. Add an auto-generated page.

      1. Click User actions in the Designer’s element area and place an Auto-generated page element after the User task element in the Process Designer’s working area.

      2. Fill out the auto-generated page properties.

        • Set Title to "Sum of numbers page."
        • Set Page title to "Sum of numbers page."
      3. Add an auto-generated page.

        1. Click in the Page Items block and select "Integer."

        2. Fill out the item properties.

          • Set Title to "SUM:."
          • Set Code to "Sum."
          • Click Process parameterSum of numbers in the Value property.
        3. Click Save to add the parameter.

  5. Click Save on the Process Designer’s toolbar.

Outcome of the example

To view the outcome of the example, run the Sum of numbers process business process.

As a result, Creatio will open the Sum of numbers page auto-generated page. The page will display the sum of 2 integers that are specified in the business process parameters.

Source code

UsrSumNumbersProcessUserTask
namespace Terrasoft.Core.Process.Configuration {
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using Terrasoft.Common;
using Terrasoft.Core;
using Terrasoft.Core.Configuration;
using Terrasoft.Core.DB;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Process;

#region Class: UsrSumNumbersProcessUserTask

/// <exclude/>
public partial class UsrSumNumbersProcessUserTask {

#region Methods: Protected

protected override bool InternalExecute(ProcessExecutingContext context) {
/* Execute operations with task parameters. */
SumNumbers = FirstNumber + SecondNumber;
/* Specify that the task was completed successfully. */
return true;
}

#endregion

#region Methods: Public

public override bool CompleteExecuting(params object[] parameters) {
return base.CompleteExecuting(parameters);
}

public override void CancelExecuting(params object[] parameters) {
base.CancelExecuting(parameters);
}

public override string GetExecutionData() {
return string.Empty;
}

public override ProcessElementNotification GetNotificationData() {
return base.GetNotificationData();
}

#endregion

}

#endregion

}


Resources

Package with example implementation