Skip to content
Last updated

Parameters

  • Add Parameter: You can add variables. The variable name can be verified directly in the script in the next step.

  • Run JS Script: You can add Javascript script here.

  • Output Format

    • String
    • Integer
    • Number
    • Boolean
    • ElementObject
  • What do these fields mean?

Output

  • Output Parameters
    • The output result of the script.
  • Execution Log
    • Start Time
    • End Time
    • Duration (ms)
    • Status (Success/Failure)

Example

Example 1: Set a random number.

// Set the range for the random number, e.g., 1 to 100
const min = 1;
const max = 100;

// Generate a random integer
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;

// Return the result to the RPA flow
return randomNumber;

Example 2: Parse element content.

Option A: Parsing JSON data (based on the tip at the bottom of the page)

// Assume this is the JSON string variable passed via "Add Parameter" in RPA.
// In actual use, replace this string with your passed variable name.
const jsonString = '{"id": 101, "name": "MoreLoginRPA", "status": "success"}';

try {
    // Parse the string into a JSON object
    const jsonData = JSON.parse(jsonString);
    
    // Extract the value of 'name' and return it
    return jsonData.name; 
    
} catch (error) {
    // If parsing fails, return an error message
    return "Parsing failed: " + error.message;
}

Option B: Parsing a DOM element (if extracting text directly from the webpage)

// Get the element on the page via CSS selector 
// (Replace '.your-target-class' with the selector you actually need)
const element = document.querySelector('.your-target-class');

if (element) {
    // Extract and return the text content of the element, 
    // removing leading and trailing whitespace
    return element.textContent.trim();
} else {
    // If the element is not found, return null
    return null;
}

[!TIP] You can pass variables generated in the project directly to AI to generate scripts. Prompt: "{} This json content, I want to extract the content of name through javascript, and finally output the value of name."