1.1.2 Code Parameter Fields

Code Parameter Fields

  1. What are Code Parameter fields?
  2. Examples:
    1. Variables from the main Code layer used inside Custom JS Code fields
    2. Configuration Values from Configurations inside Custom JS Code fields
    3. Functions inside Custom JS Code fields
    4. Any code inside Custom JS Code fields 

 

  1. What are Code Parameter fields?

Code Parameter fields are a feature inside action settings that allows you to dynamically fill action parameter values using JavaScript code. 

 

Each action has a set of parameter inputs to configure it. Typically these will be filled with static values, but in some cases, you’ll need to set these values dynamically at the time of execution. Kaholo has the possibility to use JavaScript code directly inside the action parameter fields which allows you to dynamically input parameter values. The main rule to remember is that parameters passed using JavaScript Code should be compatible, with the required by field, as all those parameters end as one request to the API of the application that we are integrating.

 Custom JS Code Field

 

To code a parameter, first toggle the Code switch, located on the upper right side of the specific parameter section. When the switch turns blue, and the text field black, the field becomes a JavaScript code field with full capabilities, including access to the Kaholo SDK. This makes it possible to access Pipeline data such as statuses, Action results, trigger payloads, or configuration. Each code field has full access to the same context as the main Code Tab. It means that from there you can call functions that are on the Code Tab.

 

  1. Examples:

 1. Calling variable from Code Tab inside Custom JS Code field

One of the great uses of the Custom JS Code fields is when you want to define one value and use it in every plugin in the pipeline. Below you have an example when in the Javascript Code Layer you have defined variable “awsRegion” instead of region chosen from the dropdown list (Standard field for Region and AWS Plugins). In this case, we defined variable on the Code tab. 

 

Code Field:                                                                            Code Tab:

                           awsRegion                                                         const awsRegion = ‘eu-central-1’

 

2. This example shows the definition of the same value but this time we are referring to the value defined in the Configurations tab

 

Code Field:                                                                       Configurations Tab:

kaholo.execution.configuration.awsRegion                                            { “awsRegion” : “eu-central-1”}

 

 

3. This example shows the way to call the function from Custom JS Field

 

Code Field:                                                                              Code Tab:

awsRegionFunction()                                                   function awsRegionFunction(){

                                                                                                        return  ‘eu-central-1’; }

Note: there is a possibility to define everything inside the code field, like function, even whole script, although this isn’t recommended way and it’s less readable