Assign Variable
C# oneliner.
Assign Variable shape can be used to assign a value from short C# expression to a variable, that can then be later used in the Process. Alternatively, it can modify a value using a single C# expression.
What is Assign Variable?
Assign Variable shape, also known as Expression shape, can be used to execute a single C# expression, and optionally save the result to a variable. The shape is useful for initializing values for a variable, updating value in existing variable, or performing small "oneliner" C# code expressions that modifies an object.
It is similar in function to variable assignment or single line of C# code in programming, supporting the same use cases as what can be used in such a situation. Instead of returning a value to a variable, the value the expression evaluates to will be assigned to the variable specified in the shape.

Usage
To use Assign Variable, add it to Process canvas and connect it to your Process, alongside other shapes, between a Trigger and a Return or Throw shape. After adding it to your Process, you can give the shape a display name, as well as define the parameters.
Most important parameters to define for Assign Variable are the variable's name and its value. Optionally you can also define a type for the variable, such as string, JObject or List<string>. Any C# primitive type or class from included libraries can be used. If data type is not defined, the type will be dynamic and thus automatically deducted at runtime.
Assign Variable is most commonly used for assigning a value to a variable in the Process, or to modify an existing value or object in a variable. It can also be used to easily promote a single value from the Process, if and when a larger dataset or whole result of an operation is not necessary to be logged or promoted.
Configuration
To set up an Assign Variable shape, add it to your Process canvas and connect it to your Process flow using Sequence flows. After this, you can configure the shape with variable's name, value and type.
The following configuration parameters exist for Assign Variable shape.
Display name
Shapes can be given a display name in Frends Processes to distinquish them from each other. Shape's display name has no technical purpose and is only for documentational and visual purposes only. For shapes returning a #result reference value, the display name can be used to specify which result is meant.
Display name is given to the shape by double-clicking it on the canvas or through its configuration parameters.
Assign Variable
Toggle option to select if the result of the C# expression should be saved to a variable. If disabled, the C# expression will be executed, but it's possible result value will not be saved, which can be useful for modifying an existing object's value. Defaults to enabled, allowing the developer to specify a name for the variable.
Expression
The C# expression to execute for the shape. Can be a single C# expression that does not use return statement or semicolons to end the expression.
Alternatively, the input field's type can be changed to text, JSON or XML to assign the variable a string value, with syntax highlighting for the selected format. Handlebars syntax can be used within the plain text input to include C# expressions.
Type
Text input field to specify the type of data for the variable. Any valid C# primitive type or class from included libraries can be given here to enforce the data type and simplify the variable's usage.
Alternatively the field can be left empty, resulting in dynamically typed variable, of which data type will be deducted at runtime.
Skip logging result and parameters
Toggle option to select if the values of this shape should be included in logging or not. Default is false. If set to true, Process Instance logs will show the result and parameter values of this shape as << Omitted >>.
Dispose at the end of the scope
Toggle option to select if the result and other memory allocations should be released after the containing scope exits. The containing scope can be the Process execution itself, Scope shape, or a single iteration of Foreach or While Scope shape.
Can be useful if the shape results in a large amount of data, allowing its early release from memory if it's not needed later in the Process.
Promote result as
Toggle option to select if the result value of this shape should be promoted in the Process Instance list, and an text input field if set to true. Default is false. Promoted values appear in the Process Instance list in their own column along with error and result values. Promoted value column is named with the text input field appearing when this is set to true.
Promoted values are always logged fully in the Process Instance view, regardless of the log level settings.
Reference Values
Assign Variable shape primarily provides a #var reference value, corresponding to the variable assigned within the shape.
In addition, the shape provides an unnamed #result reference value, which also contains the result of the expression in the shape, in case it resulted in a value being returned or assigned to a variable. If the expression did not result in a value being returned, simple "code element executed" string will be stored instead.
#var
Representing a variable in Frends Processes, #var reference values can be created as Process Variables from the Process's general parameters, or during Process flow using Assign Variable or Code Task shapes with Assign variable parameter enabled.
All methods to create variables in Frends Processes require defining a name for the variable. The variable can then be used as #var.MyVariable, if MyVariable is set as the variable's name.
#result
#result reference value can be used to access earlier shape's return value. For Scope shapes, the value is specified using Return shape, while for Task's the #result is populated directly by the Task.

When Return shape is used to end Foreach or While shapes, the expression or HTTP content values in Return shape are available through #result reference value as an array of values for each iteration.
#result reference value by default references the last Task's or Scope shape's return value. Instead of unnamed #result reference, you can also use named #result reference value.
Last updated
Was this helpful?