Skip to Content
Author's profile photo ASHISH AHIRE

How to Return Generated Value in XSODATA using XSJSLIB Modification Exit

Introduction :

For consuming HANA data on UI we usually develop XSJS , XSODATA depends on situation. As you know in every release of HANA , SAP is increasing XSODATA features. In this blog will give you basic idea how can you use XSJSLIB based modification exit for updating and returning value in XSODATA response.

Scenario :

Let’s consider a scenario we’ve created employee table which contain empid , first name , department , email …etc. For performing CRUD operation I’ve created XSODATA service. we can pass each and every information from UI except employee id because it should be generated at server side with the help of sequence / custom logic and should return at UI side after successful creation . I’ve seen many threads in which many Native Hana developer faced issue to get newly created value in XSODATA .

Objects :



XSODATA : EMS.xsodata

service  {
    "EMS"."EMS.Employee.HANATABLE::EmpPersInfo" as "Pinfo"
     create events ( before "EMS.Employee.XSJSLIB:emp_oprtn.xsjslib::usersCreate" ) //before create operation this exit will be trigger

SEQUENCE: EMS.hdbsequence

schema= "EMS";
increment_by = 1;      //  -1 for descending
start_with = 100;
maxvalue= 99999999;
cycles= false;         // when reaching max/min value
depends_on_table = "EMS.Employee.HANATABLE::EmpPersInfo";

XSJSLIB: emp_oprtn.xsjslib

function usersCreate(param){
       $.trace.debug('entered function');
       let after = param.afterTableName; // temporary table
       // Updating Employee Id Before Create operation via sequence
       let pStmt = param.connection.prepareStatement('update "' + after + '" set EID = "EMS.Employee.SEQUENCE::EMS".NEXTVAL' );

UI5 code –

var oModel= new sap.ui.model.odata.ODataModel('/EMS/Employee/XSODATA/EMS.xsodata', false);
var inputData={};
inputData.EID= '';
oModel.create('/Pinfo',inputData,null, function(odata,oResponse){
  alert("Creation successful");

Testing : Everything is ready we can check it now –

see below screenshot of debugger we’ve send just dummy EID = 1 but in response our newly created Employee id is available 🙂




Assigned tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Wolfgang Röckelein
      Wolfgang Röckelein

      Hi Ashish,

      thanks for the valuable blog!

      In the documentation regarding hdbsequence I found "The target table or view specified in the depends_on keyword must be mentioned in the SELECT query that defines the reset condition". So isn't using depends_on_table without a reset_by incorrect?

      Also it seems that depends_on_table was replaced with depends_on...



      Author's profile photo Gowthami Bhogireddy
      Gowthami Bhogireddy

      Hi Ashish

      When I try to update using xsjslib, I don't receive any response. I have tested the service using POSTMAN and I receive a 204 - No content there.

      In such a case, how do we interpret in UI5 if its successful or not?

      Author's profile photo Ankur Gokhale
      Ankur Gokhale

      Hi Ashish,


      Great post ! I have a question here. You have "EMS"."EMS.Employee.HANATABLE::EmpPersInfo"  in XSODATA. Is this a view? Because I believe that looks like sub package path.

      I am using a table, how do I need to put that in depends_on_table inside hdbsequence



      Author's profile photo Jimmy Arnold Moreno Nuñez
      Jimmy Arnold Moreno Nuñez

      Hi Ashish.

      Can I create the sequence from Hana cockpit ?

      Is this sentence necesary?


      Thanks in advance.