When defining the action flow of your action, you can assign values to variables. This behavior is implemented through the Assign element which you can drag onto your canvas from the Action Flow Toolbox.

Assigning a Value to a Variable

To assign a value to a variable simply click on the Assign element and set the Variable and the Value properties in the Properties Pane.

To set the variable do one of the following:

To set the value do one of the following:

To assign more values to variables within the same assign, repeat the procedure for next empty line of assignment that is automatically added.

Assigning Variables By Value and By Reference

When assigning values to variables, it is important to keep in mind that depending on the data type of the variables, they are handled by value or by reference.

Most of the data types are handled by value. This means that variables are using two different memory locations and the value is copied from one location to another. Changes to one of the variables will not affect the value of the other.

Example

The copy of a record by directly assigning the variables will make a copy of the record. The result is that changing the value of one record will not affect the value of the other.

The exceptions to handling by value are the Record List, Binary Data, or Object data types that are handled by reference. This means that assigning a variable to another makes both of the variables to be pointing to the same memory location. Changes to one of the variables affects the value of the other.

See also How Input Parameters are Handled in Actions and Web Blocks.

Example

The copy of a record list by directly assigning the variable of the original list to the variable of the duplicated list will put both variables pointing to the same memory location. The result is that changing the list of one of the variables will affect the list of the other variable.

The right way to do this is to iterate the elements of the original list and add them to the duplicated list. There's also a built-in function that does this job: ListDuplicate().

Auto Assign

When assigning attributes between two variables of Record data type, you would normally need to make an assignment for each one of the attributes. However, if you select the (Auto Assign '<variable name>') option of the drop-down list, Service Studio automatically adds for you all the assignments between attributes.

The (Auto Assign '<variable name>') option is only visible when you click in the drop-down list of the Variable and there is already a previous assignment between two variables of Record data type. The assignments are hinted on the previous assignment or on the currentone (if defined). The "hint" algorithm matches the left and the right hand sides of assignments with base on names and data types of the attributes.

If no assignments can be inferred, the Auto Assign option is not available.

Example

This is better explained by looking into the following examples:

CopyRecord.Contact.Name = OriginalRecord.Contact.Name

When you select (Auto Assign 'CopyRecord.Contact') in the drop-down list, new assignments will be added for each unassigned attribute:

CopyRecord.Contact.<attribute> = OriginalRecord.Contact.<attribute>.

Name = OriginalContact.Contact.Name

Where Name is a local variable of Text data type.

The Auto Assign is not available because the previous assignment is not between two elements of Record data type.

The Auto Assign is not available in the drop-down list because there is no assignment to be based on.

At any moment while defining your Assign you can check which attributes are already assigned in Select Variable window.

See Also

About Variables | Select Variable Window | Expression Editor | Assign Properties | Action Flow Toolbox