Last updated
Last updated
The Script and the Test code is available in your project in the training folder!
This is simple as that:
We do not need any Execution Property or Dynamic Property or Process Property in our script, but the Context would the right place to add those.
Dynamic Document Properties would be added to each document, not to the Context itself.
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.
Maintaining the script header information is mandatory, especially the date and author tags. This is even more important when you work in a team!
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:
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 prices
list 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:
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.
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 ).
We parse the text document into a JSON (map), so that we can access the JSON elements as properties (see ). 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().
You can copy and paste the script code into the psgAggregatePrices
script component
Check the process logs to see the log entires your script has written
Developing a real world script - using ScriptEase