Updated on 2025-08-15 GMT+08:00

Creating a Blank Script

Similar to flows, scripts are used to develop service APIs and logic. Flows are graphical and ideal for simple scenarios, while scripts are ideal for scenarios with complex service logic. You can develop TypeScript scripts online. This section describes how to create a script. This script only implements the function of requesting http://www.example.com and returning headers. No object or API is called.

Creating a Blank Script

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Logic.
  3. (Optional) Click next to Script to add a folder for the script.

    By default, scripts are stored in the root folder. Before creating a script, you can create a folder for storing the script. You can drag the script to a specified folder.

  4. Move the cursor to a script folder and click . The page for adding a script is displayed.

    If the script folder has not been created, click next to Script. The page for adding a script is displayed.

  5. Select Create a New Script, enter a script name, for example, httpTest, and click Add. The script editing page is displayed.

    Figure 1 Adding the httpTest script
    Table 1 Parameters for adding a script

    Parameter

    Description

    Name

    Enter a script name. The naming requirements are as follows:

    • The value cannot exceed 63 characters, including the prefix namespace.

      To prevent duplicate data names among different tenants, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.

    • Start with a letter and can contain only letters, digits, and single underscores (_). There is no consecutive underscore (_) and the value cannot end with an underscore (_).

    Template

    Select a script template from the drop-down list.

    • Empty: creates an empty script.
    • Demo Service Script: script for providing services externally. The script can be called directly using RESTful APIs.
    • Demo Internal Script: script containing internal library code, which can be used only by other scripts after the script is imported.
    • Empty Test Script: creates an empty test script.
    • Example pre/post install script: script executed before or after instantiated configuration data is imported during application installation or upgrade. This script is used to pre-delete, delete, and update data.
    • Demo Pre Handler Script or Demo Post Handler Script: configures access permissions of third-party systems on Astro Zero's flow, script, or operation object data APIs when the APIs are opened to third-party systems for invocation.

    Default value: Empty.

    Description

    Enter the description of the script.

    Value: 1–255 characters.

  6. On the script editor, paste the following code to the code editing area.

    import * as http from 'http' // Import the HTTP library
    let client = http.newClient() // Instantiate
    let resp = client.get("https://www.example.com/")// Request website
    console.log(resp.headers) // Print the returned headers

  7. Click in the upper part of the page to save the script.
  8. Test the script.

    1. Click in the upper part of the editor to run the script.
    2. Click in the upper right corner of the test window at the bottom of the page to return the message headers.
      0603 10:39:22.569|debug|vm[731]>>> Build #AppCube Core 24.3.0 amd64
      Built on 2024-05-08 09:54:09 
      Commit #fbbb0cef14
      0603 10:39:22.571|debug|vm[731]>>> node: 4
      0603 10:39:22.573|debug|vm[731]>>> script: Namespace__httpTest__1.0.1
      0603 10:39:22.574|debug|vm[731]>>> locale: zh_CN
      0603 10:39:22.576|debug|vm[731]>>> os timezone: Local
      0603 10:39:22.578|debug|vm[731]>>> user timezone: (GMT+08:00) China Standard Time (Asia/***)
      0603 10:39:22.580|debug|vm[731]>>> organization timezone: (GMT+08:00) China Standard Time (Asia/***)
      0603 10:39:22.581|debug|vm[731]>>> load module http
      0603 10:39:24.934|debug|vm[731]>>> 
      {
          Date: [ Mon, 03 Jun 2024 02:39:24 GMT ],
          Set-Cookie: [ __cf_bm=mZCsDLBaFW9LYtwZSHdNG7lmfqWg7eiREVGkzxP0I5M-1717382364-1.0.1.1-kxYJgrTmCAQyj7kla1aazwY6lz3QSL9R98.v_HQCdYQqw2m.zkmxYpDhenoCTFxpfMLpzhrpiPT1eCdhqEgduw; path=/; expires=Mon, 03-Jun-24 03:09:24 GMT; domain=.squadhelp.com; HttpOnly; Secure; SameSite=None ],
          Vary: [ Accept-Encoding ],
          Server: [ cloudflare ],
          Content-Type: [ text/html; charset=UTF-8 ],
          X-Frame-Options: [ SAMEORIGIN ],
          Referrer-Policy: [ same-origin ],
          Cache-Control: [ max-age=15 ],
          Expires: [ Mon, 03 Jun 2024 02:39:39 GMT ],
          Cf-Ray: [ 88dc50043f2e5355-LAX ]
      } (Namespace__httpTest.ts:4)
      0603 10:39:24.936|debug|vm[731]>>> resource limit usage:
          number of RequestSOQLQueriesAmount: 0
          number of RequestSOQLRowsAmount: 0
          number of RequestSOSLQueriesAmount: 0
          number of RequestSOSLRowsAmount: 0
          number of RequestDMLStatementsAmount: 0
          number of RequestDMLRowsAmount: 0
          number of RequestCallOutsAmount: 1
          number of RequestEmailSendsAmount: 0
          number of RequestEventSendsAmount: 0

  9. After the script test is complete, click in the upper part of the editor to activate the script.

    An activated script can be used by other scripts and flows. Inactive scripts cannot be queried by other widgets.