Handle response
Overview
The handleResponse method is an optional Groovy method that can be defined in a task or an executable. It is called automatically after an API request is completed and allows you to process the API response before the task continues.
The method receives a single ServiceAPIResult parameter, which contains the response returned by the API, including the response data and status information.
You can use handleResponse to:
- Process or validate the API response.
- Extract values from the response.
- Reuse the response data when calling additional APIs, without querying the database again.
- Perform custom logic based on the API response, such as deciding what to do next.
Groovy code
import com.ria.converter.api.executor.service.ServiceWorkEntry
//import com.riaadvisory.dih.core.api.executor.service.ServiceWorkEntry
def handleResponse(ServiceAPIResult result) {
// Log the invocation for debugging purposes
CommonEnv.logInfo('Invoking target T1_MOVIE for ' + result.getServiceWorkEntry().getColumnValue('MOVIE_TITLE'))
// Extract column and field values from the ServiceAPIResult
def colValues = new HashMap(result.getServiceWorkEntry().getColumnValues())
def fieldValues = new HashMap(result.getServiceWorkEntry().getFieldValues())
// Print column and field values for debugging purposes
println "colValues = ${colValues}"
println "fieldValues = ${fieldValues}"
// Invoke another target API using the extracted values
CommonEnv.invokeTarget('T1_DIRECTOR', 1, colValues, fieldValues)
}
| Parameter | Description |
|---|---|
ServiceAPIResult result |
Contains the result from the previous API call. The
ServiceAPIResult object provides access to details such as
column values and field values.
|
getColumnValues() |
Returns the source column values as a If the target uses different columns, you must manually populate the required values in the Groovy script. |
getFieldValues() |
Returns the mapped field values as a If a field is not provided, the target's mapping expression is used. The mapping expression can be a literal value or a column name from the Column Values map, but it cannot be an SQL function because that would require another database query. |
CommonEnv.invokeTarget() |
Invokes another target from the Groovy script using the supplied target ID, mapping ID, column values, and field values. This uses the following parameters:
|
Examples
Executable

Task

Restartability
This solution does not currently support restarting from a specific API call made in the handleResponse method.
If a failure occurs, DIH restarts from the task’s primary target, not from the API call that failed. As a result, the primary target may be called again even though it completed successfully before the failure, which can lead to duplicate data being sent to the target system.
To avoid duplicate API calls, design the source query for the primary target so that it excludes records that have already been processed successfully.