Functions

Create customized functions to utilize in Workflows

By Definition, a Function is a group of statements that, together, performs a task. In DBSync, Functions are categorized as:

  1. Standard Functions

  2. User Defined Functions

Standard Functions

Standard Functions, or built in Functions, refer to specific Function by name. Functions are available to all users of a project. If a project is imported, the same files and Functions, from the original project, are available to the cloned project.

Functions are code sensitive. When you are using Functions, the string objects must be enclosed in single quote

The Standard Functions are listed, in detail, in the iPaaS section. Click on the Standard Functions to learn about the inbuilt Functions offered by our DBSync iPaaS.

User Defined Functions

User-Defined functions are those functions that are defined by the user from the DBSync platform. Functions are used for code reuseability and to save time and space.

At present, DBSync platform supports creation of UDF in JavaScript.

Benefits

  1. It provides modularity. As a result, a user can create once and then, reuse it across any project that allows create once and reuse n number of times.

  2. Easy code reusability. You just have to call Functions by its name to reuse it.

Tutorial

Follow the video walkthrough to create and test a sample function.

Creating a User Defined Function

All User Defined Functions have to be followed with the header "//@UserDefined" for DBSync to recognize it as User Defined Function. When done so, it is populated in the UserDefined list of the "Mapping page".

  1. User has to login to DBSync iPaas and navigate to Functions page.

  2. Click on New Function. This will navigate a User to a Function Creation screen.

  3. Name a Function of his/her choice and define the Function in the space provided.

  4. Click on Save to save the User Defined Function.

Use the following code to test the function

//@UserDefined
function chooseColor(priority) {
  var color = "";
  if(priority == "High"){
    color = "Red";
  } else if(priority == "Medium"){
    color = "Yellow";
  } else if(priority == "Low"){
    color = "Green";
  }
  return color;
}
 
//@Test
function test(){
  chooseColor("Medium");}

Testing a Functions

To test a User Defined Function, it has to be accompanied by a method generally started with header "//@Test". The user must save the created Function before testing it.

The following code snippet shows the Test method required to test the User defined function for name:

Code

//@UserDefined
function fullName(firstName, lastName){
  return firstName + " " + lastName;
}
function fullName(firstName, lastName){  return firstName + " " + lastName;
}

Testing

// //@Test
function testFirstAndLastName(){//@Test
function testFirstAndLastName(){
  var firstname = "Xxxxxx";
  var lastname = "Yyyyy";
  addFirstAndLastNames(firstname, lastname);
}  var firstname = "Xxxxxx"; var lastname = "Yyyyy";  addFirstAndLastNames(firstname, lastname);
}

The following screen shows the User Defined Function along with Test method required to execute it.

  1. After writing the Test method, immediately after the UDF, it is best practice to Save. The Save button is located at the top right corner of the page .

  2. Here, a user is prompted to select the available Test Methods in a pop-up. As a result, s/he can select the appropriate name and click on "Run Tests" button.

  3. Finally, the number of code lines executed is shown on the Top ribbon.