Thursday, February 3, 2022

Looping over Unique Records in Oracle Integration Cloud

Frequently we get this requirement where we have to retrieve hundreds of rows from database or by reading a file and have to send this data to downstream application. 

Catch is we can’t send all records together as downstream application will not accept it, nor we can send one record at a time as we will end up sending too many requests to downstream application, however we can group unique records and send them at once to downstream. 

In OIC, by default for-each runs for each node and we have no way to configure it to run only for unique records. Thankfully, this can be achieved by using Global Variables, Data stitch and Xslt for-each group function in Map. Let’s see how.

For this demo –
1. I am using existing OIC service [acting as downstream app] which receives and process Employee information.
2. New Service [which we will develop] will read file from FTP which contains multiple employee’s data and process each employee’s record.
3. Input File Structure used -


Steps -
1. Create FTP connection, Test and Save
 
2. Create New Integration of Schedule type.
3. Invoke FTP connection created in step 1 to read file. Provide sample file for OIC to create schema.
    [Assuming that input file size will be < 10mb. If the file size is more than 10 mb then we
     should use download file option and then use Read file option under Stage file action]
4. Add action ‘for each’ after File Read and provide values to configure it.

5. Add action and choose call OIC, configure and select EmployeeService
6. Map from Source to target then Validate and Save.
7. Map business Identifiers and save Integration. Finally, your integration should look like this –
 
8. Activate and Test


After testing you will notice that for-each ran 8 times whereas as per our requirement it should run only 3 times.
 

This is not what we wanted 😟. So, let’s make changes in integration to achieve our requirement.

9. Deactivate integration
10. Create Global Variable of type EmployeeService say distEmpCollection

11. Before loop add a Map action, if required choose target as EmployeeService variable, will have to write for each group-by xslt function and store only unique ID. Validate and Test.

We can see that for 3 Employee records we were able to generate 2 Employee nodes as output since Source contains only 2 unique records.
 

12. Now we will overwrite this data into global variable which we created earlier using Data stitch action.
13. Open ‘for each’ action and change root element to distEmpCollection. [See now your loop will run on this xml data which contains only distEmpCollection]
 
14. Open Map and update Mapping and Finally your Integration should look like this.
 
15. Save, activate and Test Integration.




Hope this helps. 😃

2 comments: