Skip to main content
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()

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.
Returns: CRMScript.Global.Void

Row operators

Comparison operators

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.
Returns: CRMScript.Global.Void

Functions

Row operators

Comparison operators

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.
Returns: CRMScript.Global.Void

Comparison operators

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.
Returns: CRMScript.Global.Void

Row operators

Comparison operators

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

Adds a criterion on a database field to the database query.
Returns: CRMScript.Global.Void

Functions

Row operators

Comparison operators

addData(String,String)

Adds data for use in an update or insert query.
Returns: 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.
Returns: CRMScript.Global.Void
You can optionally add a function to be applied to the second field.Can only be used in update() queries.
Example:

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.
Returns: CRMScript.Global.Void

Available functions

  • count
  • avg
  • sum
  • max
  • min
  • hour
  • wday
  • upper
  • lower
  • castToVarchar
  • date
  • time

addField(String)

Adds a field to the SELECT part of the database query
Returns: CRMScript.Global.Void
You can optionally add a function to be applied to the field.

addField(String,String)

Adds a field to the SELECT part of the database query with a function to be applied to the field.
Returns: CRMScript.Global.Void

Available functions

  • count
  • avg
  • sum
  • max
  • min
  • hour
  • wday
  • upper

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 ”.”.
Returns: CRMScript.Global.Void Example:

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

Adds a HAVING clause to the database query.
Returns: CRMScript.Global.Void
You can optionally add a function to be applied to the field.

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

Adds a HAVING clause to the database query.
Returns: CRMScript.Global.Void

Functions

Row operators

Comparison operators

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.
Returns: CRMScript.Global.Void

addOrder(String,Bool)

Adds a restriction to the order on the listing of the database result.
Returns: CRMScript.Global.Void
You can optionally add a function to be applied to the field.

addOrder(String,String,Bool)

Adds a restriction to the order on the listing of the database result.
Returns: CRMScript.Global.Void

Available functions

  • Count
  • Avg
  • Sum
  • Max
  • Min
  • Hour
  • WDay
  • Upper

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.
Returns: CRMScript.Global.String - The SQL query generated by the SearchEngine.
For versions 7.0 and newer, the statement returned will be an estimate of the SQL, since the query is sent to NetServer instead.

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.
Returns: CRMScript.Global.String - The SQL query generated by the SearchEngine.
For versions 7.0 and newer, the statement returned will be an estimate of the SQL, since the query is sent to NetServer instead.

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.
Returns: CRMScript.Global.Void
Has no effect if the registry value (reg_id = 235) is set to 0.Be aware of any security implications by circumventing the NetServer.

countColumns()

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

countRows()

Returns the number of rows in the result set.
Returns: 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.
Returns: CRMScript.Global.Void

eof()

Checks if the end of the result set is reached.
Returns: 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.
Returns: CRMScript.Global.Integer

executeHTMLTable()

Executes the query and return the result as a HTML formatted table.
Returns: CRMScript.Global.String - The result as a HTML formatted table.

executeInto(StringMatrix)

Executes the query and returns the result in the matrix.
Returns: CRMScript.Global.Void

executeJSON()

Executes the query and return the result as a JSON formatted text.
Returns: CRMScript.Global.String

executeTextTable()

Executes the query and return the result as a text formatted table (similar to MySQL).
Returns: CRMScript.Global.String
have some overhead for large result sets.

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.
Returns: CRMScript.Global.Void
This is useful if you want this query to populate an array in a JSONBuilder already containing other stuff.
Example:

findAlternativeFields(String)

Finds all alternative fields given a start field. These fields can be used in <code>addField()</code> or similar functions.
Returns: CRMScript.Global.String[]

findRelations(String,Bool)

Returns: CRMScript.Global.String[]

first()

Sets the row pointer to the first item of the result set.
Returns: CRMScript.Global.Bool - False if the result set is empty, otherwise, true.

getField(Integer)

Returns the value of a field.
Returns: CRMScript.Global.String - The value of the field.
You can optionally add a function to be applied to the field when using the name as the identifier.

getField(String)

Returns the value of a field.
Returns: CRMScript.Global.String - The value of the field.
You can optionally add a function to be applied to the field when using the name as the identifier.

getField(String,String)

Returns the value of a field.
Returns: CRMScript.Global.String - The value of the field.

Functions

getFieldsJSON()

Returns fields as JSON formatted string.
Returns: 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.
Returns: 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.
Returns:

select()

Does the select-query and returns the size of the result set.
Returns: 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.
Returns: CRMScript.Global.Void

setDBDistinct(Bool)

Forces SearchEngine to use a distinct in the query.
Returns: CRMScript.Global.Void

setDistinct(String)

Makes the entries distinct so that equal tickets will not be listed.
Returns: 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).
Returns: CRMScript.Global.Void

setLimit(Integer)

Sets the limit of number of rows to receive in the result set.
Returns: 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.
Returns: CRMScript.Global.Void