Create REST API for create, external database generates ID

Hello,

I'm developing an API that should create a 'Commission' record and insert it into the table. However, the primary key "CommissionID" column needs to be generated by the external database. That is, I'm not able to assign a new ID and pass that into the CreateCommission server action, or the error "Cannot insert explicit value for identity column in table 'Commission' when IDENTITY_INSERT is set to OFF." is returned.

Currently I am implementing the CreateCommission server action as such, but I still get the error.
Is this possible?
Thank you!! 

Hi Landon,

In this scenario, you should turn off the autonumber in the entity identifier attribute(CommisionId). This allows you to insert data into the identifier attribute while inserting new rows.

Thanks,

Karthik

Karthik Jeyaraman wrote:

Hi Landon,

In this scenario, you should turn off the autonumber in the entity identifier attribute(CommisionId). This allows you to insert data into the identifier attribute while inserting new rows.

Thanks,

Karthik

Thanks for the reply. The IDs are not autogenerated in OutSystems, if that's what you mean. I apologize if I was unclear.

The column is marked as an Identifier in the SQL database. Is there a way for me to pass the object to be inserted into the SQL database without an ID, because the ID will be assigned by the SQL database?


Bump - I'm fairly new to OutSystems and kind of stuck here. I would appreciate any help.

I'm not 100% sure if this is what you need, but when you insert a new row in a table with auto_increment PK id field (at least in MySQL) you can easily get it after the INSERT with a PHP function (assuming that you're using PHP for your RESTful API) that returns it. See details for mysqli_insert_id(). There's also a OO oriented apporach.

Obviously you should implement it within the API after you make the INSERT and have return it to the frontend app.

Let me know if this is what you wanted.

The column 'CommissionId' in IntegrationStudio must be the identifier and the checkbox AutoGenerated must be on. If you 'reference' the external table in your modue, the create-action will return the generated Id.
And use the 'Convert to/from NULLValue in Database'  as default behaviour.

This ony works if the external table really generates the Id.

I think Outsystems technically generates an INSERT .... RETURNING statement in SQL.