In this post, I’ll show how to use Inputs and Attributes within a workflow. I was going to make this post more involved, but WordPress doesn’t want to display half of the images that I’ve uploaded and since it’s a getting started series I’ll keep it simple.
Create Attributes
Create a new workflow named “Inputs & Attributes”.
Select “Add parameter’. When the attribute is first created it has a name of att0 and is of type string.
Click on att0 to change its name.
Rename it to “repeatCount”.
Click on “string” to change the type to number.
Repeat this process and create another attribute with the name of “repeatDelay”. Give both of the attributes a description. You should have something similar to.
Create input
Select the Input tab and then select “Add a parameter”.
The input variable will intially be named arg_in_0. Click on the name to change it.
Leave the type as string and fill in a description. You should have.
Create scriptable task element
Select the Schema tab, drag a scriptable task element onto the arrow between the Start and Stop elements.
Now we need to bind our input/attribute variables to the scriptable task so that you’ll be able to access the values of the input/attributes in the scripting section of the scriptable task.
Select “Bind to workflow parameter/attribute”.
Select all three entries.
Select the Scripting tab and you will see the input and both attributes listed as inputs (They are listed to the right of “IN”).
Type the following into the Scriptable task input field.
for (var i = 0; i < repeatCount; i++) {
System.log(repeatText)
System.sleep(repeatDelay * 1000)
}
Notice that the input parameters are displayed as pink.
Run workflow
Start your workfow and enter the text you wish to repeat and submit.
Select the Logs tab of the workflow run and you should see the following:
The main takeaway from this post is that workflow elements such as scriptable tasks can access both inputs and attributes that are defined in the workflow. Inputs are variables that users supply or are passed in from another workflow. Attributes are variables that aren’t inputted into your workflow but are variables that your workflow can access. For example, a vCenter/VM name. When you bind an input/attribute to a workflow element like the scriptable task, it is similar to passing the input/attribute to the workflow element and the workflow element acts like a function.
Thanks, this helped me 🙂