Persistent Variable

Persistent Variable

Persistent variables are those variables that hold their last run value. It uses the Current Value as the true value for the next run. Hence, the Current Value changes in each run and gets updated each time. Persistent variables can be defined for all tasks in a Workbook or Workflow.

If a variable is not persistent, it considers the Default Value as its true value. It does not hold on to the last run value and uses the Default Value as the true value for the next run. Hence, each run is initialized from Default Value, and the Current Value remains constant at the end of each run.

(info)

Note: 

In Rubiscape, the created variables in the Workbook and Workflow are persistent by default. You can make them non-persistent on the Manage Variable page.

Adding a Variable

To understand the working of the Persistent variable, first, the variables should be added.

For this, follow the steps given below.

  1. Create a Workbook. Refer to Creating a Workbook.
  2. Add Variable1 and Variable2 using the Manage Variable window. Refer to Adding a Variable.
  3. Select the Default Value and the Current Value for the two variables. Here, Variable1 should be persistent, and Variable2 should be non-persistent.
  4. Keep the checkbox for Variable1 selected below the Make Persistent
  5. Clear the checkbox for Variable2 below the Make Persistent. Now, Variable1 is persistent while Variable2 is non-persistent.

Difference between Persistent and Non-Persistent Variables

To understand the difference between persistent and non-persistent variables, changes are made to these variables. For this, follow the steps given below.

  1. Drag and drop RubiPython on your Workbook canvas.
  2. Click the RubiPython node and click Configure.
  3. Write a simple Python code in Python Code Editor using Variable1 and Variable2. Refer to Writing Custom Code using RubiPython. Here, ten is added each to Variable1 and Variable2.


  4. Click Close.
  5. Click Save on the Function Pane of the Workbook.
    The Workbook is saved.
  6. Click Run on the Function Pane of the Workbook.
    The Workbook is run successfully. This is indicated by a green icon () on the RubiPython node.



  7. Click (x) Variable on the Function Pane of the Workbook.

    The Manage Variable window is displayed. You can see the changed current values for the two variables.

    • For Variable1 (persistent variable), the Current Value is 20 (10+10). Thus, the earlier Current Value is considered as the true value for the first run.
    • For Variable2 (non-persistent variable), the Current Value is 25 (15+10). Thus, the Default Value is considered as the true value for the first run.



  8. Perform steps 6 and 7 again on the RubiPython node to run it for a second time.
    The Manage Variable window is displayed. You can see the newly changed current values for the two variables.
  • For Variable1 (persistent variable), the new Current Value is 30 (20+10). Thus, the Current Value (20) after the first run is considered the true value for the second run.
  • For Variable2 (non-persistent variable), the Current Value is 25 (15+10). Thus, the Default Value is considered as the true value for the second run.



In Rubiscape, there are different Run commands. These are:

  • Run present on the Function Pane to run the entire Workbook or Workflow
  • RunRun from node, and Run till node in the Node Menu to run an individual node(s)

Behavior of Variables

Whether a variable behaves as persistent or non-persistent for different Run commands, there are the following cases:

Case

Variable Behavior

Description

Use the Run command on the Function Pane of a Workbook or Workflow

(As per the assigned flag in the Manage Variable window.)

  • A variable marked persistent behaves as a persistent variable
  • A variable marked non-persistent behaves as a non-persistent variable.
  • The entire Workbook or Workflow (including all the nodes) runs.
  • If you run the entire Workbook or Workflow, you do not want to hold on to each node's current value or last run value. 

Use the RunRun from node, and Run till node commands on the node menu

Both persistent and non-persistent variables behave as persistent variables.


  • When you run an individual node, you want each node to take the current value or the last run value of its previous node (if present).
  • So, it is necessary to retain the current value or the last run value each time for each node.
  • Hence, any variable behaves like a persistent variable, irrespective of the flag assigned.

To explain the cases mentioned above, let us consider an example of a Workflow. The following steps are followed in the execution of the Workbook.

  1. Follow steps 1 to 5 of Adding a Variable for adding variables Variable1 and Variable2.



  2. Drag and drop three RubiPython nodes on your Workbook canvas.
  3. Click each RubiPython node and click Configure.
  4. Write a simple Python code in Python Code Editor using Variable1 and Variable2. Refer to Writing Custom Code using RubiPython.
    Here, 100 is added to Variable1 and Variable2 in each of the RubiPython nodes.


  5. Click the Run till node command on the RubyPthon__2 node.
    Figure: Running the Workflow using Run till node command.
    The Run till node command runs the three nodes one-by-one. A green icon appears on each of the RubiPython nodes after each of them is successfully run.


  6. Click the (x) Variable on the Function Pane of the Workbook.
    The Manage Variable window is displayed. You can see the changed current values for the two variables.
    • For Variable1 (persistent variable), the Current Value is 310 (10+100+100+100). Thus, the earlier Current Value is considered as the true value for each run.
    • For Variable2 (non-persistent variable), the Current Value is 320 (20+100+100+100). Thus, even though the variable was selected as non-persistent, it takes the Current Value (and not the Default Value) as the true value for each run. It means that Variable2 behaves as a persistent variable.



    • Related Articles

    • Persistent Variable

      Persistent variables are those variables that hold their last run value. It uses the Current Value as the true value for the next run. Hence, the Current Value changes in each run and gets updated each time. Persistent variables can be defined for ...
    • Deleting a Variable

      To delete a variable, follow the steps given below. Open the required workbook. Refer to Opening a Workflow. The selected workbook canvas is displayed. Click (x) Variable in the Function Pane of the workbook. Manage Variable page is displayed. Locate ...
    • Deleting a Variable

      To delete a variable, follow the steps given below. Open the required workbook. Refer to Opening a Workbook. The selected workbook canvas is displayed. Click (x) Variable in the Function Pane of the workbook. Manage Variable page is displayed. Locate ...
    • Adding a Variable

      You can add your own variable which can be used anywhere in the workbook or workflow. The below steps mention how to add a variable in a workbook. Similar steps can be performed to add a variable to a workflow. To add a variable at the workbook ...
    • Adding a Variable

      You can add your own variable which can be used anywhere in the workbook or workflow. The below steps mention how to add a variable in a workbook. Similar steps can be performed to add a variable to a workflow. To add a variable at the workbook ...