Using Input and Output Variables
Using standard JavaScript comment techniques, you can declare input and output variable to be used within a script.
Defining Input and Output Variables in Scripts
You pass data into Salesforce B2C Commerce scripts using the
@input
annotation. You pass data out of a B2C Commerce
script using the @output
annotation.
Example 1a: Input Variable Definition
GetDefaultVariant.ds
, you define the input
variables and save the script
file.
* @input Prod : dw.catalog.Product
* @input CurrentVariationModel : dw.catalog.ProductVariationModel
The
example defines two input variables, Product
and
CurrentVariationModel
, which contain string values. The last part of the
variable definition is a description of the variable.
Example 1b: Output Variable Definition
GetDefaultVariant.ds
, you define the output
variables and save the script
file.
* @output newProduct : dw.catalog.Product
The example defines
an output variable, newProduct
, which contains a product object.
Adding Dictionary Bindings
When you have saved the script files with the input and output variables defined, script node pipelet using the script adds a Dictionary Input section to the pipelet properties with the name of the input variables and a Dictionary Output section to the pipelet properties with the names of the output variables.
Example 2: script node dictionary input and output Bindings
You bind values to the parameters by entering a string, a variable name, or an expression.
In the
example above, the input variable Prod
defined in your
script file is bound to the Product
variable in the
Pipeline Dictionary. The input variable
CurrentVariationModel
defined in your script file is
bound to the Product
variable in the Pipeline
Dictionary.
Fixing Orphaned Dictionary Bindings
When you
bind a value to a parameter, the binding is stored in the pipeline file.
If you remove script parameters, the pipeline file sometimes retains
bindings for these removed parameters. To correct this, UX Studio checks
pipelines and identifies orphaned bindings. The orphaned bindings are
reported as Warnings
in the
Problems and Markers views.
You can correct the problem by right-clicking the Warning
and selecting the Quick Fix menu option.