How to handle entity validation errors in webservice microflow

0
Hi all, I have a Mendix app for which I exposed a webservice which users can use to add a certain entity to the databas. When the submitted entity is successfully commited I want to return "true" otherwise: "false". The entity has an attribute ("name") which has to be unique. When I receive a webservice call which contains an already existing name the Webservice returns: <soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <soap:Fault> <faultcode>Server</faultcode> <faultstring>Internal server error</faultstring> </soap:Fault> </soap:Body> </soap:Envelope> And this is in the log file: Jun 28 13:45:05.547 127.0.0.1 tr10044: ERROR - WebServices: Couldn't handle input parameters Jun 28 13:45:05.551 127.0.0.1 tr10044: ERROR - WebServices: (1/19) com.mendix.core.CoreRuntimeException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: Object id: 2251799813685750, validation errors: (member: Name, message: ) Jun 28 13:45:05.551 127.0.0.1 tr10044: ERROR - WebServices: (2/19) at com.mendix.core.actionmanagement.ActionManager.executeInTransactionSync(ActionManager.java:168) Jun 28 13:45:05.551 127.0.0.1 tr10044: ERROR - WebServices: (3/19) Jun 28 13:45:05.551 127.0.0.1 tr10044: ERROR - WebServices: (4/19) Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: Object id: 2251799813685750, validation errors: (member: Name, message: ) .... Jun 28 13:45:05.560 127.0.0.1 tr10044: ERROR - WebServices: (41/41) Caused by: com.mendix.systemwideinterfaces.core.UserException: Object id: 2251799813685750, validation errors: (member: Name, message: ) This is the microflow behind the webservice: https://modelshare.mendix.com/models/c3738d14-c0c0-4ca8-94fc-20c09316e254/toevoegen-groep. I suspect Mendix loads the entity into memory in order to use it as a parameter to the microflow and fails there, before even entering the microflow which is why it doesn't work as expected. Now I have two questions: Is my suspicion correct? How to realize my requirement? Best regards, Jethro
asked
1 answers
1

It seems like your solution uses the following:

  • A single entity to store both objects in your database and incoming web service requests
  • Validation rules, to ensure uniqueness of the name attribute

I would advice against these constructs: web service call objects should not be stored in your database until validated. Validation rules are too inflexible and create hidden code which becomes difficult to maintain.

Instead, use the following setup:

  • A non-persistent entity to store the incoming web service call object
  • In the microflow, retrieve the Group object with [Name = NonPersistentGroup/Name]
    • If this is empty, you create a new Group object, commit it and send true
    • If this is not empty, you return false
answered