Getting Started

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 LocalDate class, in combination with the between method from the Duration class. Here's how you can do it:

var christmasDay = LocalDate.of(2023, 12, 25);
var currentDate =;
var days = Duration.between(currentDate.atStartOfDay(), 
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 Language Basics to continue building your understanding of B2Win Suite Scripting.

Last updated