JAMS Developer Guide
Creating Custom Workflow Activities

JAMS supports adding custom Activities to the Toolbox used in Workflow Jobs. This topic describes the steps involved in creating a custom Activity and how to use JAMSTrackingRecords to receive data at runtime. The Custom Activity designed in this article accepts one of three values at runtime: Billing, Sales, or Marketing. A Workflow Job could use this Activity to execute specific logic for the received response.

Creating an Activity Library Project

In Visual Studio, create a new Project. Select the Activity Library option, and name the Poject. In the example below, the project is named "CustomActivityLib":

The next step is to add a Code Activity to the Project. In this example, the code is named "RunMonthlyProcessing":

Writing the Activity's Logic

Now that the Activity has been added to the project it's time to write it's logic. The first step is to ensure that the project references JAMS.Activities.dll and JAMSShr.dll. Both assemblies can be found in the "X:\Program Files\MVPSI\JAMS\Scheduler" directory.

The following using statements must be added to the class:

   using MVPSI.JAMS.Activities;

   using MVPSI.JAMS;

 

This Activity should derive from "NativeActivity":

   public sealed class RunMonthlyProcessing : NativeActivity

 

The Activity will contain an OutArgument called "ProcessingType" that will get the value received at runtime:

   /// <summary>

   /// The type of Processing to Perform

   /// </summary>

   public OutArgument<string> ProcessingType { get; set; }

 

   /// <summary>

   /// Allows the activity to Induce idle.

   /// </summary>

   protected override bool CanInduceIdle

   {

     get

     {

        return true;

      }

    }

The Execute Method contains the main logic of the Activity. Below create a Workflow Bookmark along with a JAMSTrackingRecord to enable the Job to wait for a specific response at runtime before continuing:

   protected override void Execute(NativeActivityContext context)

   {

     //

     // Create a Bookmark

     //

     Bookmark delayBookmark = context.CreateBookmark(string.Format("DelayBookmark_{0}",  this.Id), new BookmarkCallback(ResumeActivity));

 

     //

     // Create a JAMS tracking Record

     //

     JAMSTrackingRecord waitBookmarkRecord = new JAMSTrackingRecord("BookmarkWait");

 

     //

     // Set the Appearance of the Activity

     //

     waitBookmarkRecord.Data.Add("Appearance", DisplayCategory.Warning);

     waitBookmarkRecord.Data.Add("BookmarkName", delayBookmark.Name);

 

     //

     // Using a ResponseType of "Select" indicates a defined list of response values

     //   while a ResponseType of "Text" would allow for a text response.

     //

     waitBookmarkRecord.Data.Add("ResponseType", ResponseType.Select);

 

     //

     // Supply the response values that should be available at runtime

     //

     waitBookmarkRecord.Data.Add("ResponseValues", "Sales,Billing,Marketing");

     waitBookmarkRecord.Data.Add("State", "BookmarkWait");

 

     //

     // Send the Tracking record

     //

     context.Track(waitBookmarkRecord);

    }

 

The following Callback assigns the OutArgument after receiving a runtime response:

   private void ResumeActivity(NativeActivityContext context, Bookmark bookmark, object data)

   {

     //

     // Set the value of the OutArgument as the received data

     //

     this.ProcessingType.Set(context, (string)data);

   }

Adding the Activity to the JAMS Workflow Toolbox

Now that the Activity's logic has been defined, build the project and copy the .dll and .pdb files into the following directories:

 • X:\Program Files\MVPSI\JAMS\Client

 • X:\Program Files\MVPSI\JAMS\Scheduler

NOTE: To run or reference the custom activity on a remote agent, copy the .dll and .pdb files into X:\Program Files\MVPSI\JAMS\Client AND X:\Program Files\MVPSI\JAMS\Agent on the remote agent server.

 

When the JAMS Client starts it will load any WFToolbox* files found in the "X:\Program Files\MVPSI\JAMS\Client" folder. In order for the new custom activity to appear within JAMS a new config file must be created. Create a new file called "WFToolbox.Custom.config" that contains the following content:

<?xml version="1.0" encoding="utf-8" ?>
<WFToolboxConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns="http://jams.mvpsi.com/v1">
    <Categories>
        <ToolboxCategoryConfig
            Name="Custom"
            AssemblyName="CustomActivityLib">
            <ToolboxItems>
                <ToolboxItemConfig
                    TypeName="CustomActivityLib.RunMonthlyProcessing" />
            </ToolboxItems>
        </ToolboxCategoryConfig>
    </Categories>
</WFToolboxConfig>

The file above tells JAMS to add a new Toolbox category called "Custom" that contains the "RunMonthlyProcessing" Activity. The next time the JAMS Client is opened the Workflow toolbox will contain the new category.

Using the New Activity

Now that the Activity has been added to the Workflow Toolbox you can test it's functionality.

  1. Create a simple Workflow Job as seen below that contains a string variable called "processType". 
  2. This variable will get the response value supplied at run time from the "RunMonthlyProcessing" Activity.
  3. Add a Switch Activity that contains a case for "Billing" and add a WriteLine Activity. Save the Workflow and Submit the Job.

 

Open the Job's Detail Window in the Monitor and view the "Workflow" tab. The "RunMonthlyProcessing" Activity will be displayed with an Orange border indicating it is awaiting a response.

To respond, right-click the activity and the following response actions should be available:

Note: Selecting "Billing" will resume the Workflow and execute the WriteLine Activity.

Creating the JAMSAssemblyPath Parameter

Now that you have created some custom workflow activities, you can define a parameter named JAMSAssemblyPath and set the value to the path where your custom workflow assemblies are located. These parameters can be defined using the Execution Method, the Folder or Job level as shown in the screenshots below.

JAMSAssemblyPath Defined as an Execution Method

 JAMSAssemblyPath Defined at the Folder Level

 

JAMSAssemblyPath Defined at the Job Level

 

See Also

 

 


Copyright © Fortra, LLC and its group of companies.
All trademarks and registered trademarks are the property of their respective owners.