# Functions

## 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 Functions](https://docs.mydbsync.com/cloud-workflow/create-your-workflow/flow-builder/standard-functions) 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 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAARCAYAAAA2cze9AAABHklEQVR4AeySu0oDQRSGf2anXJZcLM0LxFZ9A8VSsRERDXkBERtFRCF4QRAREaxE8dqIlpI8QZI2eYGkzWWXbLGwC5vdamZgYDgkZQ588DPMfBzOHBZLFYZh3Gq343qjSaLT6UoWERmk8n0f75/feH55JfFfrUkWERU55xxz+TyymQyJXC4rjFJS5LZt4/BgH1cXFRKbG+uSUkRFLo6nkxR5OvPbu3scn5yS+Pn903ajyKMoQq/fx9B1SQwGQ7M8nfnO9hbKpT0Sa6srZnm6LQvFIpaXFkkUCvNmebL+GCW77iZjoRAEgVnueR4ur29wlHwohbePL7OcMQbOLVDLsvRvlG1xHAeV8zM8PT6QKJd2tf0ocu2NCQ5ncu3wxgAAAP//IzyoMwAAAAZJREFUAwDuuTzWVg6W5AAAAABJRU5ErkJggg==) from the top panel. This opens the left menu panel.
2. Click  ![](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAAZABwDASIAAhEBAxEB/8QAGQAAAgMBAAAAAAAAAAAAAAAAAAgEBQYH/8QAKBAAAQMEAQMEAgMAAAAAAAAAAQIDBAAFBhEHEiFBCBMUMSQyNEKB/8QAGAEAAwEBAAAAAAAAAAAAAAAAAAMEBQj/xAAjEQABBAEEAQUAAAAAAAAAAAABAAIDETEEBRNBUSFhcdHw/9oADAMBAAIRAxEAPwDj9bPDuIc9zTLbZhkCxPwbhd2FS4puLTkdtbASVe6CU7KCB2UAQavPTlI4wjcp2t3lZoqtYV+OpzRjIk7Htl8eW9/5vW+26Zqc3yRhmR8q8yclPMOvWmyi3YwuKfxS1JUQ18ceO4Tvzsndbs0vF10T9D5tc97PszNfHzSO9A4AgZAySfAoGvdJVkmM33Ebs9ZMhtkmDLZP6PtKb60bOlp6gOpCtbCh2I7iqumv5jXHi+nixQOenGpHIxSFY+I2vnMxNj+Yr6Kdb2Pvev7BRpUKInl1g9KLdtAzQytEbrDgDRyL6P7CK17/ACxnUrAF8aSr0t+xrlNyi26OtwFA0hAWe/QNAhP0PFZCimkBwoqCKeSCzG4ixRrwVJuFzuN1fEq6XCTMeCEthyQ6pxQSkaSnaiToDsB4qNRRQlucXGyv/9k=) **Extend** to navigate to **Functions**.
3. Click **New** to create a new function.
4. Provide the function name and input parameters.

   <figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2FLDN0IKVvuiYXhvzirxo0%2Funknown.png?alt=media&#x26;token=0a8e112e-44ef-4033-97d4-67790300e2b4" alt=""><figcaption></figcaption></figure>
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&#x20;

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.

| <p>//@UserDefined</p><p>function CombineName(firstname,lastname)</p><p>{</p><p> return firstname+" "+lastname;</p><p>}</p><p><br></p><p>//@Test</p><p>function Test()</p><p>{</p><p> var firstname = 'Ashish';</p><p>  var lastname = 'Samant';</p><p>  CombineName(firstname,lastname)</p><p>}</p> |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### 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.

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

#### 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`.&#x20;

> **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

| <p>//@UserDefined</p><p>function fullName(firstName, lastName){</p><p>  return firstName + " " + lastName;</p><p>}</p><p>function fullName(firstName, lastName){  return firstName + " " + lastName;</p><p>}</p> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### User-Defined Function Test

| <p>// @Test</p><p>function testFirstAndLastName(){//@Test</p><p>function testFirstAndLastName(){</p><p>  var firstname = "Xxxxxx";</p><p>  var lastname = "Yyyyy";</p><p>  addFirstAndLastNames(firstname, lastname);</p><p>}  var firstname = "Xxxxxx"; var lastname = "Yyyyy";  addFirstAndLastNames(firstname, lastname);</p><p>}</p> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

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

<figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2FXDBQeAoQAgBfCbfcM857%2Funknown.png?alt=media&#x26;token=6a085564-c5c9-48da-aad4-76951b79f10f" alt=""><figcaption><p>Example Function</p></figcaption></figure>

## 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.

<figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2Fg4ZEzWe0mHrcav6x0DB3%2Funknown.png?alt=media&#x26;token=9be2081c-d8ee-45ac-aed2-b1b36e1dd4af" alt=""><figcaption></figcaption></figure>

3. 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.

<div align="left"><figure><img src="https://1036205596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv9avy716UiAsS24zOznZ%2Fuploads%2F1d04AN4m23Lm6QkcQm3f%2Funknown.png?alt=media&#x26;token=1409c930-c4f1-4352-a184-2de18b970838" alt="" width="563"><figcaption></figcaption></figure></div>

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mydbsync.com/cloud-workflow/2026_dbsync-platform/extend/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
