B2Win Suite Documentation (Under Construction)
5.4
5.4
  • B2Win Suite Documentation
  • Scripting
    • B2Win Suite Scripting Overview
    • Scripting in B2Data
      • Custom Script Nodes
        • Custom Script
        • Source Script Node (File)
        • Source Script Node (Table)
        • Source Script Node (Object)
        • If-Else Condition
        • Condition Node
      • In DataPrep
      • Properties
      • Workflow Applications
        • Workflow #1
        • Workflow #2
    • Getting Started
    • Language Basics
    • Types & Objects
      • Primitives
      • Objects
        • Instant
        • LocalDateTime
        • LocalDate
        • LocalTime
        • JsonNode
        • ObjectNode
        • File
        • SuiteTable
        • Duration
      • Arrays & Maps
      • Row, Column, StringColumn
    • Utilities
      • Date & Time
        • InstantUtil
        • GeneralDateUtil
        • LocalDateTimeUtil
        • LocalDateUtil
        • LocalTimeUtil
        • Formatting
        • Timezones
      • Math
      • StrictMath
      • NumericUtil
      • DbUtil
      • DbExecutor
      • StateUtil
      • FileUtil
      • JsonUtil
      • HttpUtil
      • NodeInputReader
      • RandomUtil
      • HashingUtil
      • CompressionUtil
      • Logging
    • Properties
    • Context and System
      • Context
      • System
    • Configurations
      • Workflow Configuration
    • Tutorial
    • Feedback
  • B2Data
    • Workflow Settings
      • General Settings
      • Global/All Properties
      • Execution Configuration
        • General
        • Runtime
        • Compiler
        • Storage
        • Clean Up
      • Permissions
    • Nodes
      • Scheduler
    • Services Configuration
      • Power BI
Powered by GitBook
On this page
  • Getting Started with B2Win Suite Scripting
  • Example 1: Hello, World!
  • Example 2: Counting Down to Christmas
  • Example 3: Simple Arithmetic
  • Example 4: Working with Strings
  • Example 5: Conditional Statements
  • Example 6: Looping
  1. Scripting

Getting Started

PreviousWorkflow #2NextLanguage Basics

Last updated 1 year ago

Getting Started with B2Win Suite Scripting

Before diving into the more advanced features, let's start with some basic examples to get you acquainted with the language.

Example 1: Hello, World!

A classic "Hello, World!" example to display a greeting message:

var message = "Hello, World!"
return message;

You will be able to see the returned value in real-time in the evaluation section below your code.

Note: By default, in the absence of an explicit return statement, scripts return the value of the last evaluated statement.

Using the return keyword, a script will return the expression that follows (or null).


Example 2: Counting Down to Christmas

For a more engaging and inclusive example, we can determine the number of days remaining until Christmas Day by utilizing the now and of methods in the , in combination with the between method from the . Here's how you can do it:

var christmasDay = LocalDate.of(2023, 12, 25);
var currentDate = LocalDate.now();
var days = Duration.between(currentDate.atStartOfDay(), 
                                christmasDay.atStartOfDay()).toDays();
return days; // This will give you the count of days until December 25th, 2023.

With this code, you can effortlessly calculate the days left until the much-anticipated Christmas Day, set for December 25, 2023. It's a fun way to keep track of the holiday season!


Example 3: Simple Arithmetic

You can perform basic arithmetic operations, like addition, subtraction, multiplication, and division. Here's an example:

var num1 = 10;
var num2 = 5;

var sum = num1 + num2;
var difference = num1 - num2;
var product = num1 * num2;
var quotient = num1 / num2;

return [sum, difference, product, quotient];
// returns an Array: [15, 5, 50, 2]

This example showcases how to perform simple math operations and return the results.


Example 4: Working with Strings

You can use and manipulate strings. Here's an example that combines strings:

var firstName = "B2Win";
var lastName = "Suite";

var fullName = firstName + " " + lastName;

return fullName; // returns B2Win Suite

This example demonstrates string concatenation to create a full name.


Example 5: Conditional Statements

Here's an example that checks if a number is even or odd:

var number = 8;
var isEven = number % 2 == 0;

if (isEven) {
    return "The number is even.";
} else {
    return "The number is odd.";
}

Example 6: Looping

Here's an example of a for loop to print numbers from 1 to 4:

var sum = 0;
for (var i = 1; i < 5; i++) {
    sum = sum + i;
}
return sum; // sum is 10 (1+2+3+4)

Ready to explore more? Turn the page to to continue building your understanding of B2Win Suite Scripting.

LocalDate class
Duration class
Language Basics