9 - Aggregate Prices Example
Developing a real world script - using ScriptEase
Step-By-Step
Setup a Test Context
The first things we need to do is to setup a test context that provides the test data, as it is normally provided by the Boomi run-time. In our case, we must create the documents that we want to pass into the script for testing( see Example Documents).

This is simple as that:
Set Test expectations
Unlike in the template, we expect only one document as output, and we have to amend our test assertion in the Test class. Feel free to add more assertions to ensure the script works as expected.
Implement the Script
We need the JsonSlurper object to work with JSON data. We create the js object instance before the documents loop because there is no need to have a new instance for each document. One js is enough for all documents.

You recognize that IntelliJ is smart enough to automatically insert the requires Imports:

Navigate to the script logic and replace Your document related code here ... with:
We parse the text document into a JSON (map), so that we can access the JSON elements as properties (see Working with JSON). The scipt's logic so far is to log the incoming data. Good enough for a first Debug Run. Set a breakpoint on line 52, navigate to the Test and Debug test01().

The execution stops at the breakpoint. See the variables and output.

Let's improve the scripts functionality and build the business logic. Amend your code, define the articles result list and business logic, and set a breakpoint on the line // << set breakpoint here
Debug your script and see the execution stopping with article == null. This is expected because - look at the Variables window - the priceslist is yet emtpy.

I think, you will find out yourself how to step over the next two lines (Single Step - F10) to stop at _setTextDocument(). While your colors might be different (depending in the IntelliJ theme you have chosen), the red line is the breakpoint and the yellow line marks the next line for execution.

More interesting to see is the Variables window where you can observe that the expect article object was added to the articles list.

Amend you code again and implement the else branch.
Set a breakpoint on the _setTextDocument() line and debug a bit: document by document. After the third document you should check the console output and the variables. You will recognize the variables are close to what we expect to see in the output JSON.

Last but not least, we must write back the articles map into one output document. So, you must move the _setTextDocument() to outside of the document loop. Before, we must convert the articles map to a Json String.
As the very last step, you can update your Test class and prettyPrint() the returned Json document:

Use the script
Do you rememeber why we did all that effort? We wanted to use that script in Boomi! Copy and paste all the script code 1:1 into the script component. Of course, the Test class is not needed in Boomi.


Last updated





