Get And Set DDP In Groovy Script
HOW TO GET AND SET DYNAMIC DOCUMENT PROPERTIES IN GROOVY SCRIPT
In this blog, we will see how to get and set dynamic document properties in Groovy script and retrieve them in the Boomi process.
What is Dynamic Document Property?
These are key/value pairs that can be set at a document level. It can be set within a certain scope and not in the entire process. The value which is set in the Dynamic document property can be used only in one branch. We cannot persist the value in the Dynamic Document property. To retrieve a dynamic document 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 Document Properties.
In this Use Case,
- We will set two Dynamic Document Properties named “First” and “Second” in set properties shape with static values as 5 and 1.
- In Groovy Script, we get those properties and add the values that are assigned to Dynamic Document Properties.
- Then, we save the result in a Dynamic Document Property named “sum” 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 document properties in set properties shape.
- Let us create by selecting the set properties shape and clicking on the + symbol as shown.
- Choose Dynamic Document Property from the drop-down.
- Give the property name as “First” and click ok.
- Now, we have to set parameters for Dynamic Document Property. Select the Dynamic Document property and choose + on parameters.
- We will have to set Type and static values in parameters. Here, we are selecting Type as Static from the drop down and Static Value would be 5. Click ok.
- After setting the value for Dynamic Document Property, it looks as follows.
- Now, let us create a second Dynamic Document Property by following the same steps from Step 8. Give the name of the Dynamic Document Property as “Second” and set the static value to 1.
- 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 DDP which is set in a set properties shape, and add the values that we have provided as static. The result will be saved in a new Dynamic Document Property named “sum” which is generated.
NOTE: DDP refers to Dynamic Document Property in this blog.
- In the below 2 steps, we get Dynamic Document Properties (i.e. First and Second) which we have set in set properties shape by using props.getProperty() method.
propValue1 = props.getProperty(“document.dynamic.user defined.First”);
propValue2 = props.getProperty(“document.dynamic.user defined.Second”);
- The DDPs that are retrieved from set properties shape are stored in propValue1 and propValue2.
We are using Integer.parseInt() method to convert the values coming from propValue1 and propValue2 into integers and store them in sum1 and sum2 reference variables.
int sum1 = Integer.parseInt(propValue1);
int sum2 = Integer.parseInt(propValue2);
int sum = sum1 + sum2;
- We can set the Dynamic document property by using the method props.setProperty() which takes 2 parameters. The first parameter would be the key named “sum” and the second parameter would be the result of sum1 and sum2 values which are coming from the above step.
props.setProperty(“document.dynamic.user defined.sum”,sum.toString())
- 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 a message, give it as Value is {1}. Here {1} would be the runtime value which comes DDP sum.
- To configure the variable as DDP sum, click on + select Type as Document Property, and click choose and select Dynamic Document Property from the drop down.
- Now, give the property name as sum and click ok.
- Now, we see that {1} is configured with DDP which is the sum 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 have received the output from DDP i.e., sum.
- Click on view source and we will be able to see the output.