Webservice; Save unique items in DB? Internal server error

1
I got a webservice with a list of entities. I'd like to have the entity items to be unique on a specific attribute "personalID". This in order to have the results from the webservice saved or updated into the database. What's the correct way to achieve this functionality? Currently duplicate items (from multiple subsequent webservice calls) are saved in the database. When I put an uniqueness constraint on the "personalID" attribute, a "Internal Server Error" is shown after webservice calls with entities already in the database. com.mendix.modules.webservices.WebserviceException: Internal server error at nW.a(SourceFile:300) at nW.b(SourceFile:136) at nW.a(SourceFile:91) at com.mendix.modules.webservices.WebserviceModule.handleWebserviceCall(SourceFile:345) And com.mendix.systemwideinterfaces.core.DataValidationRuntimeException: PersonalID should be unique at hH.a(SourceFile:203) at hL.setValue(SourceFile:234) at com.mendix.core.objectmanagement.member.MendixString.setValue(SourceFile:72) at com.mendix.core.objectmanagement.member.MendixString.parseValueFromString(SourceFile:55) at hK.setValue(SourceFile:273) at nW.a(SourceFile:405) at nW.a(SourceFile:380) at nW.a(SourceFile:359) at nW.a(SourceFile:311) at nW.a(SourceFile:275) at nW.b(SourceFile:136) at nW.a(SourceFile:91) at com.mendix.modules.webservices.WebserviceModule.handleWebserviceCall(SourceFile:345)
asked
2 answers
3

Since mendix will always store a copy of the objects provided to a published webservice you should either map the imported data to a different object or you should remove the validation and create validation microflows that are triggered during the webservice call. That way the object is allowed to be stored during the webservice call. After it has been stored you can throw a custom exception with help of the community commons.

answered
1

If I understand you correct, you're getting a number of entities, let's say "Person" objects, and they all have a "PersonalId" attribute that you'd like to make unique. Then, for each "Person" object you receive via the webservice, you want to either create it (if the PersonalId can't be found in the DB) or retrieve the object from the DB and update it.

The current "retrieve" option in the webservice mapping form doesn't support this. This is due to the way the data is structured in the runtime, and will be fixed in 4.0 if I'm not mistaken. The current correct way to implement this behavior is to use a find by Microflow. In this microflow you should search for the attribute, if found create etc. Do not map the attribute in the mapping, only set it in the Microflow if you're creating a new object.

answered