We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

New CRMScript function: SearchEngine.executeToJSONBuilder()­

Hi all, 

Just a small note to inform you about a new CRMScript function I thought would be useful:

SearchEngine.executeToJSONBuilder(JSONBuilder jb, String fields, String arrayName)

The function came about because I realized that the old se.executeJson() was too limited. Using the columnnames as fields in the json was not useful, and all column types would become strings. Also, if you needed to include more json, it would not work. This new function allows you to execute a json and populate an array in a JSONBuilder instance with the result. The fields parameter is a comma-separated list of "label:fieldType" elements, when label becomes the json attribute name, and the fieldType can be "Integer", "Float", "Boolean" or "String" (default). Consequently, you have much more control of the resulting json (Boolean for instance will become "true" or "false" without the quotes). Finally, by populating a JSONBuilder, you can include other queries or properties as well, to create a larger structure where this query is just one of multiple attributes (the arrayName becomes the name of the array).

Example code:
SearchEngine se;
se.addFields("sale", "sale_id,heading,amount");
se.setLimit(10);
JSONBuilder jb;
jb.pushObject("");
jb.addString("foo", "bar");
se.executeToJSONBuilder(jb, "id:Integer,heading:String,amount:Float", "sales");
jb.popLevel();
printLine(jb.getString());

Just submitted, so it will be part of 8.5R05.

Sverre

RE: New CRMScript function: SearchEngine.executeToJSONBuilder()­

This is great, Sverre!

Av: Eirik Rusten 2. sep 2019