> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SearchEngine

> A tool for building up SQL queries, by adding fields, criteria, and data. The fields must be given on the following form: starttablename.fieldname, for example 'ticket.title'. For tables that have foreign keys to other tables, you can reach them with the following notation: starttablename.fieldname.fieldname For example, the firstname of the primary customer of a ticket is: 'ticket.cust_id.firstname'. The company name of the primary customer of a ticket is: 'ticket.cust_id.company.name'.

A tool for building up SQL queries, by adding fields, criteria, and data. The fields must be given on the following form: starttablename.fieldname, for example "ticket.title". For tables that have foreign keys to other tables, you can reach them with the following notation: starttablename.fieldname.fieldname For example, the firstname of the primary customer of a ticket is: "ticket.cust\_id.firstname". The company name of the primary customer of a ticket is: "ticket.cust\_id.company.name".

Make sure that all fields you use that start with the same table, for example, ticket, or else you will receive a big join that you probably do not want.

For many-to-many relations there is a special notation: table1.(table2->field2a).field2b Where field2a is a field in table2 that has a foreign key to table1.

From CS version 7, the aggregate functions are no longer supported, since the query is sent to NetServer instead of directly to the database. It is possible to circumvent this by setting the reg\_id 235 to 1 and explicitly use bypassNetserver(true) in the SearchEngine. Be aware of any security implications this might cause.

## Constructors

### SearchEngine()

```crmscript theme={null}
SearchEngine
```

Initializes a new instance of the SearchEngine class.

## Methods

## addComparison(String,String,String,String,Integer)

Adds a field-comparison criterion that compares 2 database fields to a database query.

You can optionally add functions to be applied to the 2 fields.

```crmscript theme={null}
Void addComparison(String field1, String compOperator, String field2, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Row operators

  | Value          | Logical operator | Expression  | Result                                      |
  | -------------- | ---------------- | ----------- | ------------------------------------------- |
  | OperatorAnd    | AND              | A && B      | Only rows matching both conditions          |
  | OperatorNotAnd | NAND             | !(A && B)   | Rows matching 0 or 1 condition but not both |
  | OperatorOr     | OR               | A \|\| B    | Rows matching either condition (or both)    |
  | OperatorNotOr  | NOR              | !(A \|\| B) | Only rows matching no conditions            |

  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addComparison(String,String,String,String,String,String,Integer)

Adds a field-comparison criterion that compares 2 database fields to a database query with functions to be applied to the 2 fields.

```crmscript theme={null}
Void addComparison(String field1, String func1, String compOperator, String field2, String func2, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Functions

  | Function | Other name | Applies to     | bypassNetServer | Description                                  |
  | -------- | ---------- | -------------- | --------------- | -------------------------------------------- |
  | avg      | FuncAvg    | Integer, Float | yes             | aggregate, the average value of a column     |
  | count    | FuncCount  | Integer, Float | yes             | aggregate, the number of rows matching cond. |
  | sum      | FuncSum    | Integer, Float | yes             | aggregate, the total sum of a column         |
  | max      | FuncMax    | Integer, Float | yes             | aggregate, the largest value of a column     |
  | min      | FuncMin    | Time, DateTime |                 |                                              |
  | hour     | FuncHour   | Time, DateTime |                 |                                              |
  | wday     | FuncWDay   | Date, DateTime |                 |                                              |
  | upper    | FuncUpper  | String         |                 |                                              |
  | lower    | FuncLower  | String         |                 |                                              |

  ### Row operators

  | Value          | Logical operator | Expression  | Result                                      |
  | -------------- | ---------------- | ----------- | ------------------------------------------- |
  | OperatorAnd    | AND              | A && B      | Only rows matching both conditions          |
  | OperatorNotAnd | NAND             | !(A && B)   | Rows matching 0 or 1 condition but not both |
  | OperatorOr     | OR               | A \|\| B    | Rows matching either condition (or both)    |
  | OperatorNotOr  | NOR              | !(A \|\| B) | Only rows matching no conditions            |

  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addCriteria(String,String,String)

Adds a criterion on a database field to the database query

You can optionally add a row operator, priority, and function to be applied to the field.

```crmscript theme={null}
Void addCriteria(String field, String compOperator, String value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addCriteria(String,String,String,String,Integer)

Adds a criterion on a database field to the database query

You can optionally add a function to be applied to the field.

```crmscript theme={null}
Void addCriteria(String field, String compOperator, String value, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Row operators

  | Value          | Logical operator | Expression  | Result                                      |
  | -------------- | ---------------- | ----------- | ------------------------------------------- |
  | OperatorAnd    | AND              | A && B      | Only rows matching both conditions          |
  | OperatorNotAnd | NAND             | !(A && B)   | Rows matching 0 or 1 condition but not both |
  | OperatorOr     | OR               | A \|\| B    | Rows matching either condition (or both)    |
  | OperatorNotOr  | NOR              | !(A \|\| B) | Only rows matching no conditions            |

  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addCriteria(String,String,String,String,String,Integer)

Adds a criterion on a database field to the database query.

```crmscript theme={null}
Void addCriteria(String field, String function, String compOperator, String value, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Functions

  | Function | Other name | Applies to     | bypassNetServer | Description                                  |
  | -------- | ---------- | -------------- | --------------- | -------------------------------------------- |
  | avg      | FuncAvg    | Integer, Float | yes             | aggregate, the average value of a column     |
  | count    | FuncCount  | Integer, Float | yes             | aggregate, the number of rows matching cond. |
  | sum      | FuncSum    | Integer, Float | yes             | aggregate, the total sum of a column         |
  | max      | FuncMax    | Integer, Float | yes             | aggregate, the largest value of a column     |
  | min      | FuncMin    | Time, DateTime |                 |                                              |
  | hour     | FuncHour   | Time, DateTime |                 |                                              |
  | wday     | FuncWDay   | Date, DateTime |                 |                                              |
  | upper    | FuncUpper  | String         |                 |                                              |
  | lower    | FuncLower  | String         |                 |                                              |

  ### Row operators

  | Value          | Logical operator | Expression  | Result                                      |
  | -------------- | ---------------- | ----------- | ------------------------------------------- |
  | OperatorAnd    | AND              | A && B      | Only rows matching both conditions          |
  | OperatorNotAnd | NAND             | !(A && B)   | Rows matching 0 or 1 condition but not both |
  | OperatorOr     | OR               | A \|\| B    | Rows matching either condition (or both)    |
  | OperatorNotOr  | NOR              | !(A \|\| B) | Only rows matching no conditions            |

  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addData(String,String)

Adds data for use in an update or insert query.

```crmscript theme={null}
Void addData(String field, String value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## addDataField(String,String)

Adds a data field to the SearchEngine. A data field is a field assigned to another field instead of a value.

```crmscript theme={null}
Void addDataField(String field1, String field2)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can optionally add a function to be applied to the second field.

  Can only be used in update() queries.
</Note>

**Example:**

```crmscript theme={null}
se.addDataField("customer.phone", "customer.cellphone");
```

## addDataField(String,String,String)

Adds a data field to the SearchEngine. A data field is a field assigned to another field instead of a value.

Can only be used in update() queries.

```crmscript theme={null}
Void addDataField(String field1, String field2, String function)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Available functions

  * count
  * avg
  * sum
  * max
  * min
  * hour
  * wday
  * upper
  * lower
  * castToVarchar
  * date
  * time
</Note>

## addField(String)

Adds a field to the SELECT part of the database query

```crmscript theme={null}
Void addField(String field)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can optionally add a function to be applied to the field.
</Note>

## addField(String,String)

Adds a field to the SELECT part of the database query with a function to be applied to the field.

```crmscript theme={null}
Void addField(String field, String function)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Available functions

  * count
  * avg
  * sum
  * max
  * min
  * hour
  * wday
  * upper
</Note>

## addFields(String,String)

A shortcut to add multiple fields to a query. Adds all fields in the comma-separated string "fields", prefixed by "table" and a dot ".".

```crmscript theme={null}
Void addFields(String table, String fields)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
addFields("ticket", "id,title,category.fullname,cust_id.fullName");
```

## addHaving(String,String,String,String,Integer)

Adds a HAVING clause to the database query.

```crmscript theme={null}
Void addHaving(String field, String compOperator, String value, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can optionally add a function to be applied to the field.
</Note>

## addHaving(String,String,String,String,String,Integer)

Adds a HAVING clause to the database query.

```crmscript theme={null}
Void addHaving(String field, String function, String compOperator, String value, String rowOperator, Integer priority)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Functions

  | Function | Other name | Applies to     | bypassNetServer | Description                                  |
  | -------- | ---------- | -------------- | --------------- | -------------------------------------------- |
  | avg      | FuncAvg    | Integer, Float | yes             | aggregate, the average value of a column     |
  | count    | FuncCount  | Integer, Float | yes             | aggregate, the number of rows matching cond. |
  | sum      | FuncSum    | Integer, Float | yes             | aggregate, the total sum of a column         |
  | max      | FuncMax    | Integer, Float | yes             | aggregate, the largest value of a column     |
  | min      | FuncMin    | Time, DateTime |                 |                                              |
  | hour     | FuncHour   | Time, DateTime |                 |                                              |
  | wday     | FuncWDay   | Date, DateTime |                 |                                              |
  | upper    | FuncUpper  | String         |                 |                                              |
  | lower    | FuncLower  | String         |                 |                                              |

  ### Row operators

  | Value          | Logical operator | Expression  | Result                                      |
  | -------------- | ---------------- | ----------- | ------------------------------------------- |
  | OperatorAnd    | AND              | A && B      | Only rows matching both conditions          |
  | OperatorNotAnd | NAND             | !(A && B)   | Rows matching 0 or 1 condition but not both |
  | OperatorOr     | OR               | A \|\| B    | Rows matching either condition (or both)    |
  | OperatorNotOr  | NOR              | !(A \|\| B) | Only rows matching no conditions            |

  ### Comparison operators

  | Value               | Same as | Result                         |
  | ------------------- | ------- | ------------------------------ |
  | OperatorEquals      | ==      | values match                   |
  | OperatorNotEquals   | !=      | values don't match             |
  | OperatorLt          | \<      | value less than                |
  | OperatorLte         | \<=     | value less than or equal       |
  | OperatorGt          | >       | value greater than             |
  | OperatorGte         | >=      | value greater than or equal    |
  | OperatorIs          |         | values of the same type        |
  | OperatorIsNot       |         | values of different types      |
  | OperatorLike        |         | pattern found in string        |
  | OperatorNotLike     |         | pattern not found in string    |
  | OperatorContains    |         | string is present              |
  | OperatorNotContains |         | string is not present          |
  | OperatorBeginsWith  |         | string starts with             |
  | OperatorEndsWith    |         | string ends with               |
  | OperatorIn          |         | column has entries in table    |
  | OperatorNotIn       |         | column has no entries in table |
</Note>

## addJoinCriteria(String,String,String,String,Integer)

Does NOT work with NetServer. You need to bypass NetServer (see the method bypassNetServer) if you need to use this.

```crmscript theme={null}
Void addJoinCriteria(String p_0, String p_1, String p_2, String p_3, Integer p_4)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## addOrder(String,Bool)

Adds a restriction to the order on the listing of the database result.

```crmscript theme={null}
Void addOrder(String field, Bool ascending)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can optionally add a function to be applied to the field.
</Note>

## addOrder(String,String,Bool)

Adds a restriction to the order on the listing of the database result.

```crmscript theme={null}
Void addOrder(String field, String function, Bool ascending)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  ### Available functions

  * Count
  * Avg
  * Sum
  * Max
  * Min
  * Hour
  * WDay
  * Upper
</Note>

## buildSql()

Returns the SQL query generated by the SearchEngine. The query is built by \<code>addCriteria()\</code>,\<code>addComparison()\</code>,\<code>addData()\</code>, and so on.

```crmscript theme={null}
String buildSql()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The SQL query generated by the SearchEngine.

<Note>
  For versions 7.0 and newer, the statement returned will be an estimate of the SQL, since the query is sent to NetServer instead.
</Note>

## buildSql(String)

Returns the SQL query generated by the SearchEngine. The query is built by \<code>addCriteria()\</code>,\<code>addComparison()\</code>,\<code>addData()\</code>, and so on.

```crmscript theme={null}
String buildSql(String type)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The SQL query generated by the SearchEngine.

<Note>
  For versions 7.0 and newer, the statement returned will be an estimate of the SQL, since the query is sent to NetServer instead.
</Note>

## bypassNetServer(Bool)

From version 7, all queries are sent to NetServer instead of directly to the database. This function will allow you to send the queries directly to the database instead.

```crmscript theme={null}
Void bypassNetServer(Bool p_0)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Has no effect if the registry value (reg\_id = 235) is set to 0.

  Be aware of any security implications by circumventing the NetServer.
</Note>

## countColumns()

Returns the count of columns (selected fields) in the SearchEngine query.

```crmscript theme={null}
Integer countColumns()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The count of columns (selected fields) in the SearchEngine query.

## countRows()

Returns the number of rows in the result set.

```crmscript theme={null}
Integer countRows()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The number of rows in the result set.

## delete()

After adding criteria, call this to delete the items that was selected by the query.

```crmscript theme={null}
Void delete()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## eof()

Checks if the end of the result set is reached.

```crmscript theme={null}
Bool eof()
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if the end of the result set is reached; otherwise, false.

## execute()

Executes the query. Must be called to get the results.

```crmscript theme={null}
Integer execute()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer)

## executeHTMLTable()

Executes the query and return the result as a HTML formatted table.

```crmscript theme={null}
String executeHTMLTable()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The result as a HTML formatted table.

## executeInto(StringMatrix)

Executes the query and returns the result in the matrix.

```crmscript theme={null}
Void executeInto(StringMatrix matrix)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## executeJSON()

Executes the query and return the result as a JSON formatted text.

```crmscript theme={null}
String executeJSON()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)

## executeTextTable()

Executes the query and return the result as a text formatted table (similar to MySQL).

```crmscript theme={null}
String executeTextTable()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)

<Note>
  have some overhead for large result sets.
</Note>

## executeToJSONBuilder(JSONBuilder,String,String)

Executes the SearchEngine to a JSONBuilder.

The fields string can contain a comma-separated list of label:fieldType elements, allowing you to better control the resulting json. The label is the name the field gets in the json object. The fieldType can be "Integer", "Float", "Bool", or "String" (default). The json object member will be formatted accordingly, e.g. a Bool will be "true" or "false", while Integer/Float will become unquoted numbers.

The arrayName will become the name of the array in the JSONBuilder.

```crmscript theme={null}
Void executeToJSONBuilder(JSONBuilder jb, String fields, String arrayName)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  This is useful if you want this query to populate an array in a JSONBuilder already containing other stuff.
</Note>

**Example:**

```crmscript theme={null}
SearchEngine se;
se.addFields("sale", "sale_id,heading,amount");
se.setLimit(10);
JSONBuilder jb;
jb.setPrettyPrint(4);
jb.pushObject("");
jb.addString("foo", "bar");
se.executeToJSONBuilder(jb, "id:Integer,heading:String,amount:Float", "sales");
jb.popLevel();
printLine(jb.getString());
```

## findAlternativeFields(String)

Finds all alternative fields given a start field.

These fields can be used in \<code>addField()\</code> or similar functions.

```crmscript theme={null}
String[] findAlternativeFields(String fieldBeginsWith)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)\[]

## findRelations(String,Bool)

```crmscript theme={null}
String[] findRelations(String p_0, Bool p_1)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)\[]

## first()

Sets the row pointer to the first item of the result set.

```crmscript theme={null}
Bool first()
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - False if the result set is empty, otherwise, true.

## getField(Integer)

Returns the value of a field.

```crmscript theme={null}
String getField(Integer num)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The value of the field.

<Note>
  You can optionally add a function to be applied to the field when using the name as the identifier.
</Note>

## getField(String)

Returns the value of a field.

```crmscript theme={null}
String getField(String name)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The value of the field.

<Note>
  You can optionally add a function to be applied to the field when using the name as the identifier.
</Note>

## getField(String,String)

Returns the value of a field.

```crmscript theme={null}
String getField(String name, String function)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The value of the field.

<Note>
  ### Functions

  | Function | Other name | Applies to     | bypassNetServer | Description                                  |
  | -------- | ---------- | -------------- | --------------- | -------------------------------------------- |
  | avg      | FuncAvg    | Integer, Float | yes             | aggregate, the average value of a column     |
  | count    | FuncCount  | Integer, Float | yes             | aggregate, the number of rows matching cond. |
  | sum      | FuncSum    | Integer, Float | yes             | aggregate, the total sum of a column         |
  | max      | FuncMax    | Integer, Float | yes             | aggregate, the largest value of a column     |
  | min      | FuncMin    | Time, DateTime |                 |                                              |
  | hour     | FuncHour   | Time, DateTime |                 |                                              |
  | wday     | FuncWDay   | Date, DateTime |                 |                                              |
  | upper    | FuncUpper  | String         |                 |                                              |
</Note>

## getFieldsJSON()

Returns fields as JSON formatted string.

```crmscript theme={null}
String getFieldsJSON()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)

## insert()

After adding the values of the fields, call this function to actually do the insert in the database. Returns the resulting ID of the insert.

```crmscript theme={null}
Integer insert()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The ID of the newly added item.

## next()

If not the end of the result set is reached, the result pointer is set to the next line.

```crmscript theme={null}
Bool next()
```

**Returns:**

## select()

Does the select-query and returns the size of the result set.

```crmscript theme={null}
Integer select()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The number of items in the result set.

## setCallBack(String)

Sets a CRMScript function as a callback that will be used to convert the values before they are displayed in the grid.

```crmscript theme={null}
Void setCallBack(String functionName)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setDBDistinct(Bool)

Forces SearchEngine to use a distinct in the query.

```crmscript theme={null}
Void setDBDistinct(Bool p_0)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setDistinct(String)

Makes the entries distinct so that equal tickets will not be listed.

```crmscript theme={null}
Void setDistinct(String field)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setGroup(Bool)

Sets or removes a group-clause to all of the fields in the query (added by the \<code>addField()\</code> function).

```crmscript theme={null}
Void setGroup(Bool set)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setLimit(Integer)

Sets the limit of number of rows to receive in the result set.

```crmscript theme={null}
Void SetLimit(Integer number)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## update()

Use this function after \<code>addData()\</code>, which sets the values that will be modified, and \<code>addCriteria()\</code>, which do a restriction on the items to modify.

```crmscript theme={null}
Void update()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)


## Related topics

- [SearchEngine](/en/automation/crmscript/searchengine/index.md)
- [Using the SearchEngine class in ejScript](/en/automation/crmscript/searchengine/using-the-searchengine-class-blog-post.md)
- [Exploring search results](/en/automation/crmscript/searchengine/se-results.md)
- [Building a query](/en/automation/crmscript/searchengine/se-select.md)
- [GenericSearch](/en/automation/crmscript/reference/CRMScript.Native.GenericSearch.md)
- [CRMScript best practices](/en/automation/crmscript/code-quality/best-practices.md)
