Skip to Content

How to Handle Filters in Soap Operations

When an oData URL specifies filter, which has to be passed as a request parameter, then this filter expression must be retrieved from the uri and parsed in order to get the filter key and value.

Steps from Design Time tool

  1. Create an OData Service Implementation Project
  2. Create an OData Model for login operation, which can have properties CustomerId, CustomerName, Address,CategoryId,SupplierId


    3. Right click on odatasvc and choose Select data source

    4. Select the entity set and choose the query CRUD operation. Select the data source SOAP Service.


    5. Specify the wsdl file and choose the getCustomers operation from the list of soap operations and click on finish

Img3 (1).jpg

6. Right click on Query and select Define Custom Code


7. Select the script type as either javascript or groovy script


    8. The filter options specified in odata request has to be fetched in the custom script’s processRequestdata function. Initially the uriInfo object specified in the org.apache.olingo.odata2.api.uri package has to be fetched using the below function

function getUriInfo(message) {
  var uriInfo = message.getHeaders().get(ODataExchangeHeaderProperty.UriInfo.toString());
  return uriInfo;

    9. From the uriInfo fetch the filter expression as below



function parseToWhereExpression(whereExpression) {
    importPackage (;
    var FILTER = "FILTER";
    var BINARY ="BINARY";
    if (whereExpression.getKind() == 'FILTER') {
                    return parseToWhereExpression(whereExpression.getExpression());
    else if (whereExpression.getKind() == 'BINARY') {
                    var binaryExpression = whereExpression;
                    var left = parseToWhereExpression(binaryExpression.getLeftOperand());
                    var right= parseToWhereExpression(binaryExpression.getRightOperand());
                    return left + "EQ" +right;
    else if (whereExpression.getKind() == 'PROPERTY') {
                    var property = whereExpression;
                    var prop = property.getEdmProperty();
                    var returnStr = prop.getName();
                    return returnStr;
    else if (whereExpression.getKind() == 'LITERAL') {
                    var literal = whereExpression;
                    var literalType = literal.getEdmType();
                    var value = literalType.valueToString(literalType.valueOfString(
                                                                                    literal.getUriLiteral(), EdmLiteralKind.URI, null,
                                                                                    EdmLiteralKind.DEFAULT, null);
                    return value;
    else {
                    log.logErrors(LogMessage.TechnicalError, "***returning NULL****");

So, if the odata request is https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet?$filter=CategoryId eq 10,

Then the request payload will look like

         <tes:categoryid>10</tes: categoryid>

   10. Right click on Query and select Define Response Mapping


    11. Do the mapping as below


    12. Right Click on Project and select Generate and Deploy Integration Content. This will deploy the bundle.

Now fire an OData Request https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet?$filter=CategoryId eq 10 on the browser and response will give the list of customers with categoryId 10.

You must be Logged on to comment or reply to a post.