How to create an incrementing Substitution Variable
search cancel

How to create an incrementing Substitution Variable

book

Article ID: 267051

calendar_today

Updated On:

Products

Automic Applications Manager

Issue/Introduction

In Applications Manager, the use of incrementing Substitution Variables (subvar) may be required for various actions to be performed a specified number of times only. 

An incrementing subvar is a subvar thas resolves to a number that will increase by one each time the subvar is evaluated. Once it reaches a specified number, another action can be taken.

Some examples scenarios:

  • Restarting a Job an x amount of times before taking another action
  • Delaying a Job an x amount of times before skipping
  • Checking to see if a file exist an x amount of times before delaying Job each time

 

Environment

Applications Manager

Resolution

There are a couple ways to create an incrementing subvar. Both ways, increments a subvar value by one, performs and action such as restarts the Job on Abort, and once it reaches a certain value, another action is taken. 

Option 1

The first method uses 2 subvars, one to sets a value to be incremented and one to increment the first subvar value. Below is an example condition configuration:


Image shows the following 4 rows for Conditions on FAIL_TEST Job:
Order: 1; Timing: BEFORE; Performed: ONCE; Condition#1: ALWAYS TRUE; Qual: =; Condition#2: ALWAYS TRUE; Action: SET SUBVAR; Action Argument: #count_tries=0
Order: 2; Timing: BEFORE; Performed: CONTINUOUS; Condition#1: ALWAYS TRUE; Qual: =; Condition#2: ALWAYS TRUE; Action: SET SUBVAR; Action Argument: #count_tries={#increment}
Order: 3; Timing: BEFORE; Performed: CONTINUOUS; Condition#1: {#count_tries}; Qual: GT; Condition#2: 15; Action: SET SKIP STATUS; Action Argument: Max tries
Order: 4; Timing: AFTER; Performed: CONTINUOUS; Condition#1: STATUS; Qual: =; Condition#2: ABORTD; Action: RESTART ON ABORT; Action Argument: Y

Here is #count_tries subvar:

Image shows Substitution Variables: #count_tries
Name: #count_tries
Type: Numbers
Nothing else filled in

 

Here is #increment subvar:


Image shows Substitution Variables: #increment
Name: #increment
Type: Numbers
Sql statement: select {#count_tries} +1 from dual


The following behavior is expected with this condition configuration:

Condition 1 - set or resets #count_tries value to 0. This is performed only once.
Condition 2 - increments #count_tries by 1
Condition 3 - If #count_tries value is greater than 5, set SKIP status with custom status value "Max Tries". Change this accordingly.
Condition 4 - Restart on Abort status

As seen below, with this condition set up, a Job Aborts 5 times before skipping with a Max Tries status.

Option 2

The second method is more simple and parses the JobID, the subvar can be used in multiple Jobs without issue. However since it is using 1 condition, there is less options in what actions can take be taken.

In the below example, the Job restarts 5 times before no longer restarting resulting in the 5th restart staying in Abort status. Here is the condition configuration:

Image shows Conditions on FAIL_TEST:
Order: 1; Timing: AFTER; Performed: CONTINUOUS; Condition#1: {#failcount}; Qual: LT; Condition#2: 5; Action: RESTART ON ABORT; Action Argument: Y

Here is #failcount subvar. 

Image shows Substitution Variables: #failcount
Name: #failcount
Type: Numbers
Sql statement: select nvl(substr('{jobid}',length(cast ({jobid} as int))+2),0) from dual 

Behavior:

Condition 1 - Every time #failcount condition is evaluated, an unseen counter based on the JobID is incremented by 1. Once the counter is no longer less than 5, the condition action of restart Job on Abort no longer occurs and the last instance of the Job stays in Abort status as seen below