Author: Jean-Edouard Mayette

Product version: xDI 2024.1.x (implemented with 2024.1.11)


Need


There are use cases where parameters can be optional when calling a Webservice.


Summarized Solution

In the below example, the xDI published Webservice can be called to provide customers information. 

If a parameter is used, the data will be filtered otherwise the complete list will be sent.

 


Detailed Solution


Mapping definition : 


mapping


Process definition to publish as a webservice



image



To put in place optional parameters for the Webservices, 2 actions are needed :

1. A scripting to check the parameters before calling the related mapping


image


In above screenshot, if no parameter value is provided, default value is assigned; otherwise, the user value is assigned.

The assigned value is published in a new session variable (not mandatory).

 

if ('x${~/cusId}$' == 'x') {cus='0'} else {cus='${~/cusId}$'}
if ('x${~/titCode}$' == 'x') {tit='x'} else {tit='${~/titCode}$'}

__ctx__.publishVariable("~/cus_id", cus)
__ctx__.publishVariable("~/tit_code", tit)

 


2. SQL rule the filter the data


image


In the above screenshot, if the default value is used (no parameter value provided), all the table lines related to the parameter will be extracted; otherwise, a filter is done with the user value.

  

(
(T_CUSTOMER.CUS_ID = '${~/cus_id}$' and '${~/cus_id}$' <> '0') or ('${~/cus_id}$' = '0')
)
and
(
(T_CUSTOMER.TIT_CODE = '${~/tit_code}$' and '${~/tit_code}$' <> 'x') or ('${~/tit_code}$' = 'x')
)

  


As a result (with postman) for the >ebservice call :


with parameter : cusId = 1 => 1 result


image



with parameter : titcode = Mr => multiple results



image




with parameter : cusId = 1 , titcode = Mrs => no result


image