JAMS supports adding custom Activities to the Toolbox used in Workflow Jobs. This article goes through 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 will accept 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
The first step is to create a new Activity Library Project called "CustomActivityLib":
The next step is to add a Code Activity to the Project called 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 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 we 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 we can test it's functionality.
- Create a simple Workflow Job as seen below that contains a string variable called "processType".
- This variable will get the response value supplied at run time from the "RunMonthlyProcessing" Activity.
- 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:
(Selecting "Billing" will resume the Workflow and execute the WriteLine Activity)
Comments