Creating a User Defined Function

Introduction

In the walk through, let's see how a user can append First Name and Last Name. For this, the user has to follow the following steps:

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.

Following screenshot illustrates creation of a Function:

Use the following Code snippet to test the concept:

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

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 .

//@UserDefinedfunction chooseColor(priority) { var color = ""; if(priority == "High"){ color = "Red"; } else if(priority == "Medium"){ color = "Yellow"; } else if(priority == "Low"){ color = "Green"; } return color;} //@Testfunction 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++; } } } //@UserDefinedfunction combine(first, last){ return first + ' ' + last;} //@UserDefinedfunction doubleme(nu){ return 2*nu;} //@Testfunction test(){ input['data'] = {name:"rajeev", first:"gip"}; myapp.readData(); input['data'] = out['data'];// this is the straight transformation myapp.writeData();}

Last updated