Tuesday, March 8, 2022

Managing "Counters" in Boomi process

Managing "Counters" in Boomi processBoomi is very powerful and good at what it does, but sometimes it isn't clear on how to achieve certain goals. Counting a string or an element is probably one of them.

I encountered a new business requirement, that in my Salesforce-NetSuite integration pipe, I had to distinguish single-line orders from multi-line orders, then tag single-line orders with a special flag.

After digging around the web, I was able to add a counter using:
1) Dynamic Process Property
2) Data Process Shape
3) Custom Scripting within Data Process Shape

Step 1. Configure Dynamic Process Property

First, you will need to add Set Properties shape to the canvas. Add a Dynamic Process Property and give it a name. I named it 'myCounter'.

There are two methods to start your counter - by setting the value to 0, or using the updated output of the variable with the default value of 0. In the latter case, do not forget to loop your data process shape back to Set Properties shape.



Step 2. Add Data Process Shape

Now, we will need to add a Data Process shape to the canvas. The shape itself should be fairly simple, but my use case made it more complicated, because my goal is to count the number of repeating elements within a single document. And thus, I had to add Split Documents processing step to break out documents first.

Step 3. Custom Scripting

The document is finally broken down into multiple documents using Split Documents method, so now it's time for me to get the document count. You can achieve this by using Custom Scripting processing step within Data Process shape.

The original code that Boomi provides with this configuration should not be erased or modified, but we should add our counter property to this script. The tricky part is that a Dynamic Process Property's value is a string while the counter is an integer, so we need some data conversion.

Below is the final output of the code where black is the default, and red is what I have added.


import java.util.Properties;
import java.io.InputStream;
import com.boomi.execution.ExecutionUtil; // import Boomi execution library

for(int i = 0; i < dataContext.getDataCount(); i++ ) {
    InputStream is = dataContext.getStream(i);
    Properties props = dataContext.getProperties(i);
 
    // Retrieve the current myCounter value
    myCounterValue = ExecutionUtil.getDynamicProcessProperty("myCounter");
    
    // Convert myCounterValue to an integer
    int myCounterInt = Integer.parseInt(myCounterValue);
    boolean_variable = true;
    
    // Increment value by 1
    myCounterInt = myCounterInt + 1;
    
    // Convert int value back to string
    myCounterValue = Integer.toString(myCounterInt);
    
    // Set Counter
    ExecutionUtil.setDynamicProcessProperty("myCounter", myCounterValue,boolean_variable);

    dataContext.storeStream(is, props);
}

Please let me know how this worked out. If you have a better method of using counters in Boomi, please share with us!








No comments: