Send external object for External /entities

0
We have to integrate with   SQL Server Database with tables having ID as Identity Column as primary key.   We can use send external object to insert a record in the SQL Server.  WE are using the concept of external entities.    Question  -  Once we create a record in SQL table using send external entity, how do we get the ID - primary key of the record inserted in the external SQL table. ? 
asked
2 answers
0

I'll show you how it's done in Mendix, hopefully that will help you to understand how to implement it for SQL server.

 

When using External Entities and OData APIs in Mendix to Mendix communication, the service will generate the id when the API is requested to save a new resource. The response will include the server generated Id and it will be provided to the client in the response payload. So the client immediately knows the ID generated by the service.

 

Here's an mendix to mendix example.

 

Here we have one normal persistent entity with an autogenerated CustomerId attribute. This is exposed as an OData resource, and consumed in the second domain model using an external entity. As illustrated here, the server side entity contains an autonumber, the client side just sees this as a long value.

 

When creating a new customer in the client, the user provides all fields except customer id. This data is then send to the API with the microflow shown here using the send customers activity. This activity automatically detects the customer id provided in the response by the service, and by selecting 'refresh in client' the data in the client webpage will automatically show the customer id generated by the service.

 

Save external object with autonumber id

 

You can see this behavior by setting the log level of OData publish and OData consume to Trace. The next screenshot shows the API call with the data for the new object. This doesn't contain a customer id.

 

image.png

 

This next screenshot shows that the response contains the generated customer id.

 

image.png

 

If your SQL Server OData API provides the same information in the response for the POST operation, this will be used automatically by mendix to receive the generated id.

answered
0

We use ODATA service concept to connect to SQL Server. I still did not get it .  My external table has ID as identify column as primary key. SQL server automatically creates identify ID whenever we insert a record. My question is how to get this ID as a column from the external entity after it is created ? Do I get ID in the latest "latestHttpResponse"?

answered