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
- Log in to the application designer by referring to Logging In to the Application Designer.
- In the navigation pane, choose Logic.
- (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.
- 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.
- 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
- 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
- Click
in the upper part of the page to save the script.
- Test the script.
- Click
in the upper part of the editor to run the script.
- 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
- Click
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot