While working on integrations there are times you would need the need to add the functionality of Wait in OIC Orchestration process.
Sometimes the called service takes some time to come up with a response element populated and you may need to make your process wait till response is received. Lets see how to implement.
Table of Contents
The Wait Activity in OIC
The wait action enables you to delay the execution of an integration for a specified period of time. You can Use this action in scheduled and asynchronous orchestrated integrations. A typical use for this action is to invoke a specific operation at a certain time.
Though Scheduled orchestration provides that option, you wonโt find this in the app-driven orchestrations, and would not be able to add the wait activity as it will be disabled.
Then how do we make our synchronous process wait? There are few workarounds which we will see.
The Options to add time delay in OIC Synchronous Process
The most used options to add wait are
- Create a JavaScript program and add to OIC libraries.
- Create a condition and add a while loop till the condition is true and call the target service inside the loop.
1. Let see how to use javascript to add Wait in OIC
Sample JavaScript
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
return start ;
}
Save the above javascript in a .js file and upload to the libraries of oic
Once uploaded select the input and output datatypes (string in our case)
After that, this function will be visible in the user-defined functions and can be used wherever required.
When you drag this function to expression builder it will show up as ns6:sleep ( ). And you can add your time as a parameter. (your namespace can be different)
e.g ns6:sleep (60000 )
You can also use the javascript action to call within your process
The called sleep function will be part of the process flow
Run your process and it would wait for that number of milliseconds. There is a limit to the parameter and the process may not wait for longer periods, resulting in Timeout Error. So use this for short time waits.
2. Using a Conditional Loop for Wait in OIC
Sometimes there are rest services whose payload values change as it undergoes some transaction within the application. A common example is PO requisition not having PurchaseOrder when itโs created but after some time the element PurchaseOrder get populated after the internal process within the application gets completed.
And your requirement is to fetch the PO number in the Flow for further processing. The initial Rest call to the requisition service will give you null for PO number.
- Create a variable (e.g povar) and assign the response of get porequistion po number element (is null initially) to povar
- Create a while loop with condition povar = null
- Call the po req service again inside the loop
- Assign the output of PO number element to povar inside the loop again.
When executed this loop will continue till the PO number is generated and assigned to the povar variable which can be used further.
3. Create a Counter loop
You can also create a counter for loop and inside the loop call a OIC dummy process which does not do any processing. Use the For loop for that number of times which can suffice your wait time.
With the above 3 methods, you can make your App driven orchestration process wait and apply these logic in different scenarios.
Suggested Readings
- OAuth Authentication in OIC
- more OIC articles
- Creating App driven orchestrations Oracle doc
FAQs
Why is the Wait Activity Disabled?
The Wait activity is disabled in App Driven orchestrations. Try using scheduled orchestrations.
How much time we can wait?
For Short periods otherwise the processes timeouts.