All Products
Search
Document Center

DataV:use-global-variables

Last Updated:Dec 02, 2024

This topic describes how to use a global variable. You can use a global variable as a static value, an asynchronous value as a variable reference, an interaction event parameter, or a filter reference.

Note

The global variables feature is a new feature of the 7.0 version. You can use the feature based on the new version of the console.

Prerequisites

  • You have logged on to the DataV console.

  • Entered Canvas Editor

  • Created two global variables var_1 and var_2

Pass as static value

  1. On the Canvas Editor page, click the Global Variables tab.

  2. Click var_1 Variable and set Source to Static Value.

  3. Modify the content of the initial value to hello.

  4. Refresh the imageicon next to Data Response Result.

  5. After the system responds, check that the response result is modified content: hello.

Passing asynchronous values as variable references

  1. On the Canvas Editor page, click the Global Variables tab.

  2. Click var_1 Variable and change the initial value to datav-hello.

  3. Click var_2 Variable and set Source to Data Source Request.

    • If you select API as the data type, use the following procedure.

      1. Set Request Method to GET and Input URL to https://datav.com/:var_1.

        Note

        The URL is an analog URL when the data type is API, which is not accessible. For more information, see the actual URL.

      2. Use the F12 function keys on the keyboard to open the call panel.

      3. Switch to the Network tab.

      4. Refresh the imageicon next to Data Response Result.

      5. Check the Name field on the Network tab again to check whether the Request URL on the Headers tab on the right is a multiple interface. image

      6. Check the query > api result of the current interface Payload tab for the set value of the var_1 variable. image

    • If you set the Data Type parameter to Compatible with MySQL Database, perform the following steps:

      1. Select Existing Data Source. You can also recreate a data source. For more information, see Data source management.

      2. Enter the following SQL expression.

        select var_1 as value
      3. Refresh the imageicon next to Data Response Result to view the response results.

Note
  • If the Data Source Type parameter is set to Static Data or CSV File, global variables are not supported.

  • If the data source type of your widget is API, the system directly assigns a value to the variable whose name is the same as the callback ID.

  • DataV provides the global variable auto-completion feature. When you configure a data source, enter a colon (: ). The editor displays the names of all configured variables on the current screen. You can use the up and down arrow keys to select a callback ID and then press Enter. When there are a large number of interactive components on the screen, this feature can help you quickly and easily use global variables.

image

Pass as an interaction event parameter

  1. In the upper-right corner of the Canvas Editor page, click Quick Search.

  2. Enter Button and Title to add two widgets to the canvas. image

  3. Select the Button widget and click the Advanced tab in the right-side Settings panel.

  4. Turn on the On Button switch in the Interaction Events section.

  5. Select the Global Variable var_1 under the Update to Variable field. image

  6. Go to the Blueprint Editor page. The global variable and the Button component are automatically connected by a dotted line, and the reference relationship between the two global variables is displayed.

    Note

    After you remove the reference relationship of a global variable, the dotted line in the blueprint is automatically deleted.

    image

  7. In the left-side navigation pane, click the Layer Nodes tab. Drag and drop General Title to the blueprint.

  8. It can be seen that the global variable var_2 is connected to the generic header as a solid line. image

    Note

    Solid lines can be deleted, and dashed lines cannot be deleted.

  9. You can add logical nodes and logical combinations to process the obtained data.

Filter Reference

Note

The getCallbackValue of the new DataV service is the same as that of the getLocalValue DataV service. To be compatible with the old DataV service, the getLocalValue is retained. We recommend that you use getCallbackValue first.

  1. In the upper-right corner of the Canvas Editor page, click Quick Search.

  2. Enter Button and Title to add two widgets to the canvas. Repeat the operation to get the button and generic title components again. image

  3. Click the Button widget and change the widget names to getLocalValue and getCallbackValue Value.

  4. Click the Common Title widget and change the widget names to Common Title -1 and Common Title -2.

  5. Click the Global Variables tab and add two global variables named name and test. and set the static values separately.

    • name variable

      [
        {
          "value": "The name variable is obtained. "
        }
      ]
    • test variable

      [
        {
          "value": "The test variable is obtained. "
        }
      ]
  6. Set the text content of the two buttons to Get test by getLocalValue and Get name by getCallBackValue. image

  7. Click the imageicon in the upper-left corner to go to Blueprint Editor.

  8. Connect components. image

  9. Add a filter and set the processing method of the Serial Data Processing node.

    • getLocalValue

      return getLocalValue('test');
    • getCallbackValue

      return getCallbackValue('name');
  10. Click Preview in the upper-right corner of the page to view the details of data retrieval. 回到哦_Trim

FAQ

Q: What can I do if I cannot obtain the return value after I configure global variables on the canvas editing page and the data query fails?

A: The canvas editing page cannot trigger the event and obtain the return value. Therefore, the request fails. You can view the callback value by using one of the following methods:

  • Preview the project. View the callback value in the URL, or click the Network tab in the browser console and obtain the value in the response.

  • Edit the project. Add test parameters next to the URL of the visual application to test the data.

    https://datav.aliyun.com/v/editor/216? parameter name=parameter value