Assigning values to variables from outside of workflow

After being declared in a workflow, values can be assigned to the variables from where the workflow is kicked off.

The following example demonstrates how a workflow variable's value can be set in a script include, business rule, or UI action:
 
//Declare an instance  of workflow.js 
var wf  = new Workflow ( ) //Get the workflow id 
var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
//Start workflow, passing along name : value pair(s) for mapping to variable 
//where input_var_name is the name of the variable declared in gear menu 
//and input_var_value is whatever that value should be for this execution of 
//workflow
wf. startFlow (wfId , null , "Workflow Name" , {input_var_name : input_var_value } ) ;
Another example that demonstrates a more readable way of passing multiple variables involves declaring an object, adding the names/values to the object, and passing it:
//Declare an instance  of workflow.js 
var wf  = new Workflow ( ) 
//Get the workflow id 
var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
//Start workflow, passing along object containing name/value pairs mapping to inputs expected by the workflow 
var vars  = { } ;
vars. input_var_name1 = input_var_value1 ;
vars. input_var_name2 = input_var_value2 ; 
// add as many variables as your workflow is expecting, then pass the object
wf. startFlow (wfId , null , "Workflow Name" , vars ) ;

Assigning Values for Subflow Inputs from inside of a Main Workflow

If a workflow that accepts inputs is called from within another workflow, those input values can be set from the workflow canvas within the UI of the workflow activity. Each input variable declared for a subflow will have a text box input area displayed on the activity. Within these text boxes, the variables can be set with any value either from the scratchpad or from within the current record.

For more information, see Workflows used as subflows.

Reading the Value of a Workflow Input Variable

The value of a Workflow input variable is accessible anywhere within the workflow that accepts javascript by dot walking the current workflow object:
var readValue = workflow.inputs.variable_name;