action parameter query validation

How do I do input parameter validations. I have an action line shown below and want to validate that the input number range is between 1 and 7 days. and if not prompt again for the correct value. This varable is later made part of of bash script, but prefer validation to be done before passing it on to the script port of the fixlet.

action parameter query “DAY” with description "Number of days cmd is valid " with default value “1”

Something along the line of (syntacticly)

while day is >1 <7
do
action parameter query “DAY” with description "Number of days cmd is valid " with default value "1"
done

Suggestions, THis is my first reach into action parmeters

Do you want your Action to ‘safely fail without doing anything’, or do you want to prevent the user from even being able to supply a bad value and prevent the Action from being taken at all?

The first is the easiest. In the Action Script itself

action parameter query "DAY" with description "Number of days cmd is valid " with default value "1"
continue if {exists (parameter "DAY" of action) whose (it as integer >= 1 and it as integer <= 7}

If DAY is not an integer, or not between 1 and 7, the Action Script will exit at that point and the action result will be marked as Failed.

The second option is a bit harder. Well, at least harder to do in the Console. There is an option known as Parameterized Fixlet where one can actually put the operator input in an HTML textbox in the Description tab of the fixlet, and call a bit of JavaScript when the operator hits the “Take Action” button to either validate the value and proceed, or give them a message that they must enter or correct the value before the Action can be taken.

@JGStew has a writeup on using Parameterized Fixlets at How to use Parameterized Fixlets

The Console doesn’t have an editor for this, so you’d have to actually export a .BES file, modify the Description HTML and script there, and re-import it.

It’s a very powerful feature though - for example if you have OS Deployment and Bare Metal Imaging, a lot of the Tasks/Fixlets in that site use Session Relevance queries to populate HTML drop-down lists in those fixlets with the names of OS images you may deploy, so you can “choose” the image rather than having to know its name.

2 Likes