Skip to Content
Author's profile photo Tejesvi DVR

Handling SOAP $top and $skip with Custom Script

In odata – > soap $top and $skip operations are supported provided there is a web service operation which can return the In corresponding response. The operation must take an input parameter and return the Web Service response.

Steps from Design Time tool

  1. Create an OData Service Implementation Project
  2. Create an OData Model for getSalesOrder operation, which can have properties CustomerID, SalesOrderID, Note etc.

          salesOrder (1).JPG

    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.

       Salesorderdt (1).JPG

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

        SalesorderWSDl (1).JPG

    6. Right click on Query and select Define Custom Code

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

        SalesorderCS (1).JPG

     8. Get the $top/$skip value from the uriInfo and form the corresponding input hash map/Soap Body to the web service as shown below. A hash map must be created in processRequestData function with key being top and value being $top value got from the UriInfo and in case of Skip A hash map must be created in processRequestData function with key being skipand value being $skip value got from the UriInfo

set the Hash Map to message body.


function processRequestData(message) {
  //Import statements
  importPackage(com.sap.gateway.ip.core.customdev.logging);
  importPackage(com.sap.gateway.ip.core.customdev.util);
  importPackage(org.apache.olingo.odata2.api.uri);
  importPackage(java.util);
  importPackage(com.sap.gateway.core.ip.component.commons);
  uriInfo = message.getHeaders().get("UriInfo");
    var startEntitySet = uriInfo.getStartEntitySet().getName();
    var top = "";
    var skip = "";
    if (uriInfo.getTop() != null)
      top = uriInfo.getTop();
    if (uriInfo.getSkip() != null)
      skip = uriInfo.getSkip();
    var keypredicate = "";
  parentMap = new LinkedHashMap();
  parentMap.put("CustID", "");
    parentMap.put("CustType", "");
    parentMap.put("top", top);
    parentMap.put("skip", skip);
    message.setBody(parentMap);
  
  return message;
}

If the odata request is https://localhost:8083/<Name SPACE>/<Project Name>;v=1/SalesOrderSet?$top=10

Then the soap request body looks like

<soapenv:Body>
   <web:getSalesOrders>
     <web:CustID></web:CustID>
     <web:CustType></web:CustType>
     <web:top>10</web:top>
     <web:skip></web:skip>
   </web:getSalesOrders>
</soapenv:Body>

if the odata request is https://localhost:8083/<Name SPACE>/<Project Name>;v=1/SalesOrderSet?$skip=2

Then the soap request body looks like

<soapenv:Body>
   <web:getSalesOrders>
     <web:CustID></web:CustID>
     <web:CustType></web:CustType>
     <web:top></web:top>
     <web:skip>2</web:skip>
   </web:getSalesOrders>
</soapenv:Body>

   9. Right click on Query and select Define Response Mapping, Enter the Description for the mapping and click on OK.

         ResponseMap (1).JPG

    10. Do the mapping as below

        SOmapping (1).JPG

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

Now fire an OData Request https://localhost:8083/<Name SPACE>/<Project Name>;v=1/SalesOrderSet?$top=10 on the browser and response will give the list of top 10 sales Order entries.

Now fire an OData Request https://localhost:8083/<Name SPACE>/<Project Name>;v=1/SalesOrderSet?$skip=2 on the browser and response will give the list of Sales Order entries with 2 records Skipped.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.