A newer version of this documentation is available.

View Latest
March 23, 2025
+ 12

Introduction

Creating the N1QL User-Defined Function

Before you can run the JavaScript function you have created (see Creating a JavaScript Library), you will need to create a N1QL User-Defined Function to reference it. You can create a N1QL User-Defined Function by using:

For more information on N1QL User Defined Functions in general, read User-Defined Functions

  1. Access the UDF screen from the administration console.

    navigate to udf query
  2. Click on the + add function link from the UDFs screen.

    library list

    which will display the Add Function screen.

    add function dialog
  3. Use the Namespace drop-down lists to select the bucket and scope where your Javascript function resides.

  4. Fill in the Function Name of your N1QL User-Defined Function.

  5. Leave the Parameters as they are.

    The …​ in the parameters box denotes a variable length list of parameters. This is why you don’t have to fill in this field.
  6. Select Javascript for the function type. A field will appear in the dialog with a list of available libraries in the namespace you selected.

    add function dialog switch to javascript

    From this list select the library containing your function.

  7. Enter the name of the JavaScript function in the Library Function Name field.

The N1QL User-Defined Function will take the same scope as the JavaScript UDF it is referencing.

Having created your N1QL User-Defined Function, the next step is to use N1QL statement to call the function.