Skip to Content

Error while executing a DB query with a custom Exits in create process

Hi experts.

I have a service with XSODATA,

service {
"cdsMyEntity.MyEntity" as "MyEntity" create events ( before "PortalProveedor.services_js:lib.xsodata.proveedores.xsjslib::idCreate" );	
}

The function XSJSLIB generate the sequecuence:

function idCreate(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 ubigeoID = "MY_SCHEMA"."MY_SEQUENCE".NEXTVAL' );
       pStmt.executeUpdate();
       pStmt.close();
}

When I call the create method in my controller I get the error:

{"error":{"code":"500","message":{"lang":"en-US","value":"Error while executing a DB query"}}}

This is because, the ID parameter wasn't updated.

Can you help me?

Thanks in advance.

60dxz.png (33.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Sep 03 at 08:13 AM

    As written in other replies to that question (which you added as comment to a lot of other questions), an update on a volatile table is not allowed (the before and after tables used for OData exists are volatile tables).

    What you can do to reach your goal:

    Take over the control for the whole insert logic by replacing the standard insert logic.

    service {
    "cdsMyEntity.MyEntity" as "MyEntity" create using "PortalProveedor.services_js:lib.xsodata.proveedores.xsjslib::idCreate";	
    }

    Within the XSJS function read the transferred data records, add the ID from the sequence and insert it into your entity table.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 02 at 05:42 AM

    Hi Jimmy,

    I'm guessing that your ID is key, hence, it cannot be updated. So that's why your update operation is failing.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.