Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Custom Engine Activity

  • Last UpdatedJun 10, 2024
  • 5 minute read

AVEVA Work Tasks provides an interface called IActionRun which can be implemented in the class file of a custom activity to develop a AVEVA Work Tasks engine activity.
The Engine Activity gets executed in Runtime by the Workflow Engine exe. No human intervention is required while executing the Engine Activity.

Procedure

Dll Reference

Workflow.NET.NET2

SampleProperty

Namespace Used

System

System.Collections.Generic

System.Text

Workflow.NET

Workflow.NET.Interfaces

Workflow.NET.Engine

Workflow.NET.Engine.Interfaces

To create Custom Activity

  1. Go to Start->Visual Studio->New->Projects->Class Library->SampleCustomAction. This step will create a Class Library project in the path specified by the name SampleCustomAction.

  2. Add the following references:

    Workflow.NET.NET2.dll from [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\bin

    SampleProperty which is created in the previous topic of "Custom Property" from [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\bin

  3. Create a class file CustomAction.cs under the project.

  4. Copy the following code in CustomAction.cs and build the project.

    CustomAction.cs

    using System;

    using System.Collections.Generic;

    using System.Text;

    using Workflow.NET;

    using Workflow.NET.Interfaces;

    using Workflow.NET.Engine;

    using Workflow.NET.Engine.Interfaces;

    namespace SampleCustomAction

    {

    public class CustomAction :IActionRun

    {

    #region IActionRun Members


    /// <summary>

    /// This is maintained for backward Compatibility

    /// </summary>

    /// <returns></returns>

    public IActivityWebUIHandler GetActivityWebUIHandler()

    {

    throw new Exception("The method or operation is not implemented.");

    }



    //// <summary>

    /// The AVEVA Work Tasks workflow engine exe service calls this method to execute the action.

    /// </summary>

    /// <param name="ExecutionID">Execution Id for the workflow for the current running workflow instance.</param>

    /// <param name="ExecutionDetailsID">Execution details id for the current running action for the particular running workflow instance.</param>

    /// <param name="CurrentContext">Workflow engine context which contains the details of the Workflow.</param>

    /// <param name="CurrentAction">Current action object, This object has entire details like properties collection used in this action. We can access the property value from the properties collection using the CurrentAction object.</param>

    /// <param name="InlinkOutput">This is the Previous Action's output which leads to this action.</param>

    /// <param name="Retrying">Indicates whether attempts will be made to reexecute this action. Will always be false.</param>

    /// <param name="Output">

    /// Output of the current action. This is the return value of the current action.

    /// The actions that have conditional routing must assign a value to this parameter.

    /// The workflow engine routes the workflow execution based on this output.

    /// </param>

    /// <returns>The Return Value of the Run method is ActionResult. There are two modes of Action Execution one is Completed  and the other one is Sleep mode. If the Return value is ActionResult.Completed then the Engine will alert the specified output  and the status of the Action will be completed in database. If the Return value is ActionResult. Sleep then the Engine will alert the specified output and the Action status will not be completed in the database.</returns>

    /// <remarks>

    /// The workflow engine executes an action by calling this method for the action.

    /// Workflow.NET provides a set of inbuilt actions. The list of actions can be

    /// extended for an application by developing the custom actions that implement the

    /// IActionRun interface. The custom action should to be added to the

    /// Actions.xml in the workflow elements directory for the application, to be able

    /// to use it in the process design.

    /// </remarks>

    public ActionResult Run(int ExecutionID, int ExecutionDetailsID, Context CurrentContext, Workflow.NET.Action CurrentAction, string InlinkOutput, bool Retrying, out string Output)

    {

    string customActivityPropertyValue = "";

     

    //First Check for the Existence of the property in the Current Action this check is must

    //for backward compatibility reasons and for any change in Actions.xml

     

    if (CurrentAction.Properties.Contains("Sample Property with Expression"))

    {

    Property prop = (Property)CurrentAction.Properties["Sample Property with Expression"];

     

     

    Workflow.NET.SampleProperty.SampleProperty sampleProperty = (Workflow.NET.SampleProperty.SampleProperty)prop.PropertyHandler;


    //Gets the value entered for the property

    customActivityPropertyValue = sampleProperty.Value;

     

    }

    //Displays the property value information in the Logger


    CurrentContext.log.LogInformation("@#@ The Value of the sample property set in the custom activity is :" + customActivityPropertyValue);



    //Output of the current action. This is the return value of the current action.

    //Suppose if you want to have conditional routing must assign a different value to this Output parameter.


    if (customActivityPropertyValue.ToUpperInvariant() == "YES")

    Output = "Success";

    else

    Output = "UnSuccess";


    return ActionResult.Completed;

     

    }


    #endregion

    }

    }

  5. Place the dll in the [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasksbin folder.

  6. Open the Actions.xml file from [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\WorkflowElements\Default\en-US\Actions\XML\ and configure for the Custom Activity under Custom Activities category.
    It is recommended to save the Custom Activity definition as a separate XML file. This ensures that when you log on to the Enterprise Console after an upgrade, the existing Custom Activity definition is retained. You can use the following sample code as a reference while creating the XML file.

    <?xml version="1.0" encoding="utf-8" ?>

    <actionsdata>

    <version number="3.0"/>

    <category name= "My Custom Activities" sortorder="10"  image="custom.gif">  

    <action name="AbortWorkfow">

    <description>Used to abort a workflow</description>

    <image resourcename="icon-Control-Runtime-Workflow.png"></image>

    <handler classname="CustomAction.AbortWorkflow" assembly="C:\ProgramFiles\Skelta\BPM.NET\Bin\CustomActions\CustomAction.dll"></handler>

    <properties>

    <property name="Application" displayname="Repository Name" type="workflowmemo" mandatory="true" helpstring="Name of the Repository."> </property>

    <property name="Workflow" displayname="Workflow Name" type="string" mandatory="true" helpstring="Name of the Workflow."> </property>

    <property name="ExecutionID" displayname="Execution ID" type="workflowmemo" mandatory="true" helpstring="Execution ID of the workflow instance that needs to be aborted."> </property>

    </properties>

    <return>

    <value helpstring="Workflow Aborted">Workflow Aborted</value>

    <value helpstring="Workflow cannot be aborted">Workflow cannot be aborted</value>

    <value helpstring="Couldn't Abort Workflow">Couldn't Abort Workflow</value>

    </return>

    </action>

    </category>

    </actionsdata>

    While configuring the Custom Activity, we need to specify the image filename of PNG type of size 40x40 for the custom activity which should be in the following folders:

    [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\WorkflowElements\Default\en-US\Actions\Images\Normal\Large,
    [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\WorkflowElements\Default\en-US\Actions\Images\Selected\Large, and
    [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\BPMUITemplates\Default\ActivityImages

    <action name="CustomActivity" displayname="Custom Activity">

    <description>Custom activity. </description>

    <image resourcename="bell.png"></image>

    <handler classname="SampleCustomAction.CustomAction" assembly="bin\SampleCustomAction.dll"></handler>

    <properties>

     <property name="Sample Property with Expression" type="SampleProperty" mandatory="true">

     <choice>Yes;Yes</choice>

     <choice>No;No</choice>

     </property>

    </properties>

    <return>

     <value helpstring="Success">Success</value>

     <value helpstring="UnSuccess">UnSuccess</value>

     </return>

    </action>

    Note: Suppose while configuring the Custom Activities in the Actions.XML file if you do not want to use any properties within the Custom activity, it is mandatory to specify the empty properties tag, as shown in the sample code below.

    <action name="CustomActivity" displayname="Custom Activity">

    <description>Custom activity. </description>

    <image resourcename="bell.png"></image>

    <handler classname="SampleCustomAction.CustomAction" assembly="bin\SampleCustomAction.dll"></handler>

    <properties></properties>

    <return>

     <value helpstring="Success">Success</value>

     <value helpstring="UnSuccess">UnSuccess</value>

     </return>

    </action>

    Note: Make sure to set the class name and assembly correctly for the Custom Activity. Classname="Namespace.Classname" and assembly="assembly name that you will get after building the Project".

  7. Open the Process Designer and the activity should get displayed under the Custom Activities Category. 

  8. Now you can drag and drop the activity to the Process Designer and set the property value and deploy the workflow.

  9. Once you Execute a Workflow using the Custom activity you can see the set value of Property in the Logger Console after the custom activity gets executed.

Output

Related Links
TitleResults for “How to create a CRG?”Also Available in