Implement an Activity that Calculates a Logarithm

Implementing a custom activity allows you to build a reusable, completely custom behavior to augment the existing activities that come with Geocortex Workflow.

In this article, you will learn how to create a custom activity that calculates the logarithm of a number with a given base.

Prerequisites

Follow the instructions in the Web Applications SDK page to set up your development environment.

note

A working knowledge of TypeScript is recommended before extending Workflow for web-based hosts.

Set up Activity Skeleton

To create a new activity:

  1. Open the Workflow activity SDK in Visual Studio Code
  2. Run npm run activity in the terminal.
  3. When prompted enter the name of the activity you would like to create and press Enter. For example, CustomActivity.
  4. Open the newly created src/activities/CustomActivity.ts file.

Implement the Activity

The npm run activity script creates a custom activity with some dummy inputs and outputs. By changing the inputs, outputs, execute logic, and tags, you can create your own custom activity that has an easy to use interface in the Geocortex Workflow Designer.

First, let's change the inputs and outputs to properties that make sense for calculating a logarithm.

note

Block tags are used to provide descriptions for inputs and outputs in the Geocortex Workflow Designer.

src/activities/CustomActivity.ts
export interface CalculateLogInputs {
// @description The base of the logarithm. Defaults to the natural log.
base?: number;
// @description The number to calculate the logarithm for.
// @required
value: number;
}
export interface CalculateLogOutputs {
// @description The logarithm output.
result: number;
}
// @category Custom Activities
// @description Calculates the logarithm of a number with an optional base.
export class CalculateLog {
static action = "your:unique:namespace::CalculateLog";
static suite = "your:unique:namespace";
async execute(inputs: CalculateLogInputs): Promise<CalculateLogOutputs> {
return { result: 0 };
}
}

Next, modify the execute method of the activity to calculate the logarithm of a number given an optional base

src/activities/CustomActivity.cs
export interface CalculateLogInputs {
// @description The base of the logarithm. Defaults to the natural log.
base?: number;
// @description The number to calculate the logarithm for.
// @required
value: number;
}
export interface CalculateLogOutputs {
// @description The logarithm output.
result: number;
}
// @category Custom Activities
// @description An activity that calculates the log of a number with the given base.
export class CalculateLog {
static action = "your:unique:namespace::CalculateLog";
static suite = "your:unique:namespace";
async execute(inputs: CalculateLogInputs): Promise<CalculateLogOutputs> {
return {
result:
Math.log(inputs.value) /
(inputs.base !== undefined ? Math.log(inputs.base) : 1),
};
}
}

Deploy the Activity

Follow the instructions to build the activity pack and deploy it.

Test the Activity

Once your activity pack is hosted and registered, your custom activity should appear in the activity toolbox in Geocortex Workflow Designer alongside the built-in activities, and can be used in the graphical interface like any other activity.

Now you can build a workflow that uses your new custom activity!

note

You can download this demo workflow that uses the custom activity and then import it into the Geocortex Workflow Designer. You will have to deploy the custom activity and form element for it to function. This workflow assumes you are hosting the activity pack with the dev server on https://localhost:57999/.

Next Steps

Now you know how to build a basic Workflow activity for web applications. Next, you can learn how to access app properties in an activity, build custom form elements, use the ArcGIS API for JavaScript in your activities and more.

Implement a Custom Form Element

Implement a custom form element for applications like Geocortex Web

Add a Layer to the Map with a Custom Activity

Access application properties like the map in custom activities for Web Applications

Use the ArcGIS API for JavaScript in an activity.

Use the ArcGIS API for JavaScript in an activity or form element

Reference other Third Party Libraries

Reference other third party libraries in your activities and form elements