AX1592

SetSharedVariable function

Sets the value of a named shared variable, and returns the variable value into the cell.

This function is only for use in composite Axiom form configurations, where there is a parent form with one or more child forms displayed using the Embedded Form component. Shared variables provide a way to pass information between the parent form and the child forms.

Syntax

SetSharedVariable("VariableName", "Value")

Parameter Description

VariableName

The name of a particular shared variable for which you want to set the value.

Value

The value to be used for the shared variable.

Whenever the SetSharedVariable function is evaluated, the value specified in the Value parameter is set as the variable value, overwriting any existing value for the variable.

All non-numeric entries must be placed in double quotation marks, unless you are using cell references to reference the text held in another cell.

Shared variable values

Variables and their values can be defined using the following methods:

  • SetSharedVariable function: Each time this function is evaluated, it sets the current value of a named shared variable to the value defined in the function, overwriting any existing value for the variable. This method takes precedence over any other method of setting the variable value.

  • Interactive component: An interactive form component, such as a combo box, can be configured to store its value using a named shared variable. Each time the component value is submitted to the source file, it sets the current value of the shared variable to the component value, overwriting any existing value for the variable.

  • Apply Shared Variable command: A button in an Axiom form can be configured to use this command, which sets the value for one or more named shared variables. When a user clicks the button, the variables are set to the specified values, overwriting any existing value for the variables.

  • GetSharedVariable function: If no value currently exists for a named shared variable when this function is evaluated, then the value of the variable is set to the value defined in the DefaultValue parameter of the function. This approach only works once, when the variable has no defined value. Once the variable has a value, the DefaultValue parameter is no longer evaluated and cannot affect the value of the variable.

Variable values can be set within the parent form or within any embedded child form. Once the variable value is set, it is then available to all forms within the shared form context, though the form must be updated in order to reflect a changed variable value. For more information see Sharing variables between parent and child forms.

Remarks

  • Only one form in the shared form instance should contain a SetSharedVariable function for a given variable name. For example, the parent form can contain a SetSharedVariable function and the child forms can contain a GetSharedVariable function, or vice versa. If more than one form contains a SetSharedVariable function for the same variable name, then the variable value will not be shared between those forms because each form will set its own value as it is updated (and from the user perspective, the last form updated will win).

  • Generally speaking, shared variables are stored in memory as strings. If you want the return value to be presented as a number or date, cell formatting and/or additional conversion functions may be necessary. For more information on special behaviors when returning shared variable values, see Sharing variables between parent and child forms.

  • SetSharedVariable is a volatile function.

Examples

=SetSharedVariable("PlanCode","42000")

This example sets the value of the shared variable PlanCode to 42000 (and the function also returns this value). In real-life use cases, the value 42000 would most likely be returned using a data lookup query, and then that return cell would be referenced in the function, such as: =SetSharedVariable("PlanCode",Variables!D24)

This example would be used in the parent form to identify the current plan code for the shared form context. The child forms displayed in the Embedded Form component would then use the GetSharedVariable function to reference this value.