Skip to main content

Pre-run preparations

Before you run the SearchEngine query, you need to consider these 3 questions and possibly add some code:
  • Should you run against NetServer with sentry rules, or do you require extended access and need to query the database directly (onsite only)?
  • Do you need to convert the values you get back? If yes, consider writing your own function and register it as a call-back.
  • Do you want the results in a specific format or is the default sufficient? This determines which flavor of execute() you call.

Void bypassNetServer(Bool p0)

All queries are by default now sent via NetServer. bypassNetServer() allows you to circumvent NetServer and go directly to the database. Benefits:
  • Slightly faster
  • Extended access to data
Draw-backs:
  • No access to virtual (constructed) fields, such as emailAddress
  • Must handle security yourself
Before you make the call, you must also set the registry value (reg_id = 235) to 1 (“Allow sentry to be bypassed”). Call it a double safe-guard.
Accomplish the same using CRMScript.
Since you can’t bypass security in CRM Online, you can only use this bypass mechanism onsite. For Online, use the dynamic archive provider instead of SearchEngine.
Be aware of any security implications! You are running queries outside sentry restrictions, and might get access to data not intended for your eyes.

Void setCallBack(String functionName)

Register you CRMScript function to convert data values as they come back. The function must be declared before calling setCallBack().

Run

Integer execute()

Must be called to get the results.
If you need formatting, consider using one of the following methods instead. When you have your result, it is time to explore the data.

Run and format the result

The following formats are available:
  • StringMatrix
  • text table (similar to MySQL)
  • HTML table
  • JSON (with or without JSONBuilder)

Void executeInto(StringMatrix matrix)

Runs the query and returns a 2-dimensional string array. This is one of the built-in classes/complex data types of CRMScript.

String executeTextTable()

Runs the query and returns a text-formatted table in a continuous string.
executeTextTable() will have some overhead for large result sets!

String executeHTMLTable()

Runs the query and returns an HTML formatted table in a continuous string.
Result:
(Line breaks have been added for presentation. They are not there in the result set.)

String executeJSON()

Runs the query and returns a JSON formatted string. If you wish better control with the resulting JSON, use executeToJSONBuilder() instead.
This example will produce JSON looking something like this:

Void executeToJSONBuilder(JSONBuilder jb, String fields, String arrayName)

Runs the query and passes the result through a JSONBuilder. This gives you more control over the resulting JSON. A comma-separated list of label:fieldType elements:
  • label - the name the field gets in the JSON object
  • fieldType can be any of the simple CRMScript types (Integer, Float, Bool, String). The JSON object member will be formatted accordingly
arrayName: Becomes the name of the array in the JSONBuilder.
This is useful if you want to populate an array in an existing JSONBuilder.
This example will produce JSON looking something like this: