Functions

Create custom functions to streamline your workflows

Introduction

DBSync Cloud Workflow Functions are reusable components that give you power to execute specific additional operations within your 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 you to create custom functions as per your specific integration requirement. Unlike built-in functions, UDFs provide flexibility to define your own logic and processing rules. All User Defined Functions begin with the //@UserDefined header so DBSync can recognize them. This ensures they are populated in the UserDefined list on the Mapping page.

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

Refer Standard Functionsarrow-up-right to learn more about the inbuilt functions.

Key Features

  • Customization – Write your own functions to handle specific data operations.

  • Reusability – Create once and use across multiple workflows.

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

  • Integration Support – Process data from both cloud and on-premise applications.

Create User-Defined Function

All User Defined Functions must be preceded by //@UserDefined for DBSync to recognize them as User Defined Function. When done so, they are populated in the UserDefined list of the Mapping page (Automated Task → Flows → Transform and Write (Configure) → Maps).

  1. To access User Defined Functions, click from the top panel. This opens the left menu panel.

  2. Click Extend to navigate to Functions.

  3. Click New to create a new function.

  4. Provide the function name and input parameters.

  5. Write the function using Javascript.

  6. Save and Test the function to ensure proper execution.

Your User Defined Function is ready to be deployed within a workflow to automate data processing.

Example 1

The following example helps a user to get the full name. Below is the code snippet of a User Defined Function and Test method to execute it.

//@UserDefined

function CombineName(firstname,lastname)

{

return firstname+" "+lastname;

}

//@Test

function Test()

{

var firstname = 'Ashish';

var lastname = 'Samant';

CombineName(firstname,lastname)

}

Example 2

The following example explains how to use user defined functions and public functions and how to call public functions from User Defined Functions. The below mentioned code snippet is of a user defined function and a test method.

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();

}

Test a User-Defined Functions

To test a User Defined Function, the Function must be followed by the test method. The test method must start with the header //@Test.

Note: Ensure that you save the Function before testing it.

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

User defined function Code

//@UserDefined

function fullName(firstName, lastName){

return firstName + " " + lastName;

}

function fullName(firstName, lastName){ return firstName + " " + lastName;

}

User-Defined Function Test

// @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 the Test method required to execute it.

Example Function

Miscellaneous

  1. It is a best practice to Save the Functions after writing the Test method. The Save button is located at the top right corner of the page.

  2. When you click Test, you will be prompted to Select Test from the available Test Methods in a pop-up. Select the appropriate test and click Run Tests.

  1. Once the tests are completed, the number of code lines executed is shown in the Top ribbon. The color of the ribbon is green or red based on the success or failure of your test.

Last updated