Writing custom actions for Workflow

When using Extender Customizer or Developer Edition, you can write or import custom workflow actions. Workflow actions are Python Extender Scripts that follow certain rules. For details on Extender scripts, refer to Extender Scripts

Naming Extender scripts used as Workflow Actions

User defined Custom Workflow Actions must contain the string “Workflow” in their name to allow Extender to identify them as Workflow Actions:

[MODULE NAME].Workflow.ActionName

ActionName should be a short descriptive name with no spaces.

Tip: For details on Extender modules, refer to Extender Modules

Scripts return value

The scripts that define the custom actions are expected to return 0 for success, 1 for failure.

Note:

The result from a custom action determines whether the workflow will follow a True or False decision branch.

Traditionally, 1 represents True, 0 represents False.

However, Workflow custom actions return 0 = True, 1 = False.

This falls in line with the 0 = success, 1 = failure convention prevalent in Sage 300 SDK development.

Therefore, for a custom action to direct a workflow down a True branch, it must return 0 (not 1).

Workflow actions and parameters

Use Parameter at the top of the script to define parameters and field names in the grid

Actions have up to 4 parameter fields

In the workflow template, you can assign a value to the parameter, up to 250 characters for each parameter.

Parameters are called P1, P2, P3 and P4. Each is given a label in the script.

Copy

Parameter Labels in workflow action

## P1 Template
## P2 To
## P3 CC
## P4 Subject # leave blank to use the template subject
## P1.FinderView=VI0008
## P1.FinderField=MSGID
## P1.FinderFields=MSGID,TEXTDESC,COMMENTS,BODY

Workflow actions can have finders for the parameters.

You need to configure FinderView for the Sage 300 view storing the details, FinderField for the key field and FinderFields for the fields you want to view in the finder grid.

Use FinderOrder to set the View Index for the FinderField

Use FinderFilter to filter the records.

Look at the Workflow.AssignColour or the Workflow.SendEmail workflow actions for example scripts.

 

Copy

Finder for workflow action parameter

## P1 Customer # for a finder to select an active customer setup in AR
## P1.FinderView=AR0024
## P1.FinderField=IDCUST
## P1.FinderFields=IDCUST,NAME
## P1.FinderOrder=0  #Key number
## P1.FinderFilter=SWACTV=1 #valid filter string including FIELDNAME=VALUE.
## P1.FinderFilter=IDGRP="RTL"  #example with a string

Examples: 

If you want to start a workflow when a Customer's address details are updated, you can configure a workflow on each address field you want to track. However, this would create a workflow record for each field. So you would need to approve change to each field separately. You could also attach a workflow to an {UPDATE} view operation and the workflow would include a series of Evaluate actions to identify which fields have changed. While this would work for 2 or 3 fields, it might become cumbersome for all the fields that make up an address.

You could write a custom action "HasAddressChanged" that would return 0 if any address field has changed, 1 if no address field has changed.