Get And Set DPP In Groovy Script
HOW TO GET AND SET DYNAMIC PROCESS PROPERTIES IN THE GROOVY SCRIPT
In this blog, we will see how to get and set dynamic process properties in the Groovy script and retrieve them in the Boomi process.
What is Dynamic Process Property?
These are key/value pairs that can be set at the process level. It can be set and used anywhere in the process. We can persist the value of the previous execution in dynamic process property and can retrieve it for the next executions. To retrieve a dynamic process property, we must remember its name and type it in the field, function, or script that we are using. There is no limit to setting Dynamic Process Properties.
In this Use Case,
- We will set two Dynamic Process Properties named as “First” and “Second” in set properties shape with static values as 3 and 5.
- In Groovy Script, we get those properties and add the values that are assigned to Dynamic Process Properties.
- Then, we save the result in a Dynamic Process Property named “Count” which is generated in the script.
Now, let us see the steps to get and set dynamic process properties in the Groovy script and retrieve them in Boomi.
Step 1: Log on to the Boomi platform (https://platform.boomi.com/) with the required credentials i.e., Email Address and Password.
Step 2: Once logged into the Boomi platform, we will be able to view the Home page.
Step 3: Now, click on Services followed by Integration. We will see the Build page. Click on New.
Step 4: Once, clicked on New, we will be able to see three fields i.e., Type, Component Name, and Folder.
- Select Type as process as we are building a process. Component Name and Folder can be given based on your choice (i.e., which name to be given and where do we want to create the process). Click on Create.
Step 5: We see that the process gets created with a start shape which is configured with AS2 Shared Server by default.
Step 6: Select the start shape and choose No Data. Click ok.
Step 7: Search for the Set Properties shape in the search pallet. Drag and drop the shape onto the process canvas and place it after starting the shape.
Step 8: We will now create dynamic process properties in set properties shape.
- Let us create by selecting the set properties shape and clicking on the + symbol as shown.
- Choose Dynamic Process Property from the drop-down.
- Give the property name as “First” and click ok.
- Now, we have to set parameters for the Dynamic Process Property. Select the Dynamic Process property and choose + on parameters.
- Here, we are selecting Type as Static from the drop down and Static Value would be 3. Click ok.
- After setting the value for Dynamic Process Property, it looks like as follows.
- Now, let us create a second Dynamic Process Property by following the same steps from Step 8. Give the name of the Dynamic Process Property as “Second” and set the static value to 5.
- After setting the values, it looks as follows.
- Click ok.
Step 9: To write a Groovy Script, drag and drop the data process shape onto the process canvas and click ok.
Step 10: Select the data process shape and click +.
- Choose Process Type as custom scripting from the drop-down. Click on edit.
Step 11: Now, we will be able to see the command prompt as shown in the screenshot.
Step 12: Now, we are writing a groovy script to get DPP which is set in set properties shape, and add values that we provided as static. The result will be saved in a new Dynamic Process Property named “Count” which is generated in the script.
NOTE: DPP refers to the Dynamic Process property in this blog.
- In the below 2 steps, we get Dynamic Process Properties (i.e., First and Second) which we have set in set properties shape and will convert the values into integers by using Integer.parseInt() method and store it in the first and second reference variables.
int first = Integer.parseInt(ExecutionUtil.getDynamicProcessProperty(“First”));
int second = Integer.parseInt(ExecutionUtil.getDynamicProcessProperty(“Second”));
- We can set the Dynamic process property by using the method ExecutionUtil.setDynamicProcessProperty() which takes 3 parameters. The first parameter would be the key named “Count” and the second parameter would be the result of the first and second values which are coming from the above step and the third value is Boolean i.e., whether we want to persist the value or not. True implies persisting the value and False indicates not persisting the value.
ExecutionUtil.setDynamicProcessProperty(“Count”, (first + second).toString(), false)
- Add the script in the command prompt and click OK.
Step 13: Now, Drag and drop the message shape onto the process canvas.
- Select the shape and in the message, give it as Value is {1}. Here {1} would be the runtime value which comes to DPP Count.
- To configure the variable as DPP Count, click on + select Type as DPP, and give the name i.e., Count as shown below. Click ok.
- Now, we see that {1} is configured with DPP which is the Count generated in the script and holds the result. Click Ok.
Step 14: Drag and drop the stop shape after the message shape to indicate the end.
Step 15: Now, test the process by selecting the atom.
- We see that the process has been executed successfully and has received the output from DPP i.e., Count.
- Click on view source and we will be able to see the output.