Dynamically map an object to an XML element using export mapping

0
Coverages and their attributes are stored within the application domain model in normalized entities. This allows for the application to be very flexible. Within the CoverageAttributes entity there are over 300 unique attributes that can be displayed to the user. An XML data extract is built as a snapshot of the data at various points in the user’s workflow. The XML schema for the snapshot has the coverage attributes as specific elements in the schema. The problem that I am having is mapping the CoverageAttribute object to the corresponding element using export mapping. For example, IRPM is the specific element that is defined in the schema and is the first attribute in the CoverageAttributes entity above. Within the application, the IRPM coverage attribute is in the CoverageAttributes entity with a Code of IRPM and a value associated to it. We would like to be able to dynamically generate the mapping to a static attribute.   Questions 1. Is there a way to have a generic entity that would be able to dynamically map to an attribute to be exported? 2. Are we able to map an object to an attribute using a microflow? 3. Are there other ways to create an export a XML?   UPDATE: We eventually went with a generic approach when creating the xml document. This allowed the document to be close to the source systems structure and allowed for a simpler entity. I did try to use a java action to take the values from the generic coverageattribute entity and insert them into the xml entity where the coverageattribute name matched the xml entity attribute name. 
asked
3 answers
1

Jason,

To answer your questions:

1) No, not in a default way that you mean here

2) No, it's not possible to map fields using a microflow, only converting is possible

3) There are but not without additional steps for the domain model.

There are 2 approaches I would consider:

1) In the domain model create an entity with the needed attributes (from the xml schema) as non-persistent objects. In you microflow fill the entities with the copy of the values needed from the persistent entities. It would be trivial to retrieve the attribute records needed and set the non-persistent attributes based on the values. Then in the export mapping use the non-persistent entities to map to the xml file.

2) The other option would be to leave the domain model intact but to create a java action that will generate the xml file. THis is considerable more work than the previous option, but would allow for a clean domain model and still have the control over the xml file. This does require some java skills, but is not too difficult to achieve.

I personally would go for the first option, this would allow you to control the create of your xml file with standard Mendix functionality. If however the amount of data you are trying to export is large then the java route would be the better alternative as this does not require additional data to be created and would be a lesser strain on performance of your functionality.

Hope this help you in implementing a solution.

answered
0

Jason,

You can obtain objects for an export mapping using a microflow.  That approach is outlined in this page of the documentation:  https://docs.mendix.com/refguide/export-mappings

However, if I understand your question correctly, you would still need to create an export entity in Mendix that contains the attributes to be exported (lets call it CoverageAttributesExport).  Then you could use a microflow to retrieve the appropriate CoverageAttributes objects (from your Mendix domain model) to populate CoverageAttributesExport.  Once populated, your microflow would simply return the CoverageAttributesExport object (could be a non persistent entity) and it will be exported.

Hope that helps,

Mike

 

answered
0

I solved this problem once by creating a string whcih contains the XML. So build the XML yourself in a microflow. The advantage when doing that in a microflow is that other developer can see what you are doing.

Regards,

Ronald

 

answered