Groovy Consoles

When developing logics, it may be useful to test (evaluate) individual code snippets. For that purpose, you can utilize one of the two Pricefx Groovy consoles available in Studio. Functionally, they are the same, but they differ in extra functionality: one supports input functions and the other PA queries. Technically, they both execute the code as if you would run a test execution of a logic with a single element where you pasted your code.

If you do not want to depend on a logic.json editor window and prefer to have the console in a separate window, you can utilize the PA SQL console (you can hide the SQL editor).

api.find()

For a better user experience of api.find() results, wrap the result returned by api.find() the with api.jsonEncode(result) on the last line (= return) of the Groovy console.


Groovy Console in logic.json

This console can be useful if you want to try out the input related functions (like api.input(), api.stringUserEntry() etc.) which return the values entered in the parameter tab.

  1. Open the logic.json editor.
  2. Navigate to the Groovy console tab.
  3. Type or paste the code snippet you want to examine.
  4. Evaluate the code snippet by clicking the icon  at top left (or pressing Ctrl+Enter).
  5. Once the snippet works as expected, you can copy it and paste into your logic element.

PA SQL Console

In addition to Groovy Console (in the logic editor) there is also the PA SQL Console (in IDEA Tools). This console was originally developed to simplify development of Analytics queries using SQL, but it can be used for all purposes except for input related functions (for those the console in logic.json is designed).

You can check here that a piece of your logic will work, that a data type is correct, what the result data type of a variable will be etc. And, of course, you can run PA queries here.

  1. Go to IDEA Tools and select PA SQL Console.
  2. Select the Datamart / Data Feed / Data Source to query.
  3. Choose the mode using the Use SQL button. This example shows the SQL mode.
  4. Click the "table" icon next to it and select columns to use.
    (warning) Select only those columns you really want to work with. The larger number, the bigger performance impact.
  5. In the upper pane of the window enter your SQL query.
  6. Click the Generate Groovy SQL element button. It executes a template and pre-generates a code in the bottom pane.
  7. Customize this code for your use case. 
    There is a placeholder "__SQL__" which is then at runtime replaced by the content in the upper pane.
    The last line toResultMatrix is there just to display the result, you can remove it.
  8. Run the query by clicking the icon at top right (or pressing Ctrl+Enter).
  9. You can then copy the lines from the bottom pane into your logic to create a real element. You need to replace the "__SQL__" with the content of the upper pane (SQL).

Found an issue in documentation? Write to us.

Â