Functions

Create customized functions to customise your workflows

Introduction to Functions

Functions in DBSync Cloud Workflow are reusable components that allow users to execute specific operations within their integration processes. They help streamline workflows by reducing redundancy and enabling efficient data processing. Functions can be leveraged to transform, manipulate, and validate data as it moves between different applications.

User-Defined Functions

User-Defined Functions (UDFs) allow users to create custom functions from the ground up, tailored to their specific integration needs. Unlike built-in functions, which come pre-configured within DBSync, UDFs provide flexibility by letting users define their own logic and processing rules.

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

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

Key Features of User-Defined Functions

  • Customization – Users can write their own functions to handle specific data operations.

  • Reusability – Once created, functions can be used across multiple workflows.

  • Scalability – Supports complex logic for handling large-scale data transformations.

  • Integration Support – Functions can process data from both cloud and on-premise applications.

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. Navigate to the Functions section within DBSync Cloud Workflow.

  2. Click on Create New Function.

  3. Define the function name and input parameters.

Example Code
  1. Write the function logic using the provided scripting language.

  2. Save and test the function to ensure proper execution.

  3. Deploy the function within a workflow to automate data processing.

Example 2

The following Example helps a user to define the color priority. Below is the code snippet of a User Defined Function and, Test method to execute it .

//@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");}

Example 3

The following Example 3 explains using user defined functions and public functions and calling public functions from user defined functions, below is the code snippet of a user defined function and Test method to execute it.

input['type'] = {newid:"", newid: "", name:"string", first:"string", id:"int"};
out['type'] = {newid: "", newid: "", name2:"string", first2:"string", surname: "string", id2:"int"};input['type'] = {newid:"", newid: "", name:"string", first:"string", id:"int"};
out['type'] = {newid: "", newid: "", name2:"string", first2:"string", surname: "string", id2:"int"};
 
 
var myapp = {
 
   //@UserDefined
 doubleme: function(nu){
  return 2*nu;
 },
 
  //@Public
  readData: function(){
 print(input['data'].name+'---'+input['data'].first);
 
 out['data']= [
          {name2:"rg1", first2:"gu1", surname: "string1"},
           {name2:"rg2", first2:"gu2", surname: "string2"},
           {name2:"rg3", first2:"gu3", surname: "string3"}];
 
 },
 
  /*
    --------------------
    |  name2 | first2  |
    ---------------------
    |  rg1   | gu1  |
    ---------------------
    |  rg2   | gu2  |
    ---------------------
    |  rg3   | gu3  |
    ---------------------
  */
  //@Public
  writeData: function(){
    if (out['data']==null){
        out['data']=[];
    }
 
   index=0;
   for each (r in input['data']){
    print(r.name2+'--'+r.first2);
    currentId = 123 + index;
    currentName = r.name2 + index;
    currentFirst = r.first2 + index;
    out['data'].push({"id": currentId, "name2": currentName, "first2":currentFirst});
    index++;
   }
  }
 
}
 
//@UserDefined
function combine(first, last){
 
  return first + ' ' + last;
}
 
//@UserDefined
function doubleme(nu){
  return 2*nu;
}
 
//@Test
function test(){
 input['data'] = {name:"rajeev", first:"gip"};
   myapp.readData();
    input['data'] = out['data'];// this is the straight transformation
   myapp.writeData();
}

Testing 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 a 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.

Example Function

Last updated