How to add a list with jsonobjects to an object in a worflow?

0
Hello, I want to add a list of object(s) to 1 object in a workflow to export it is a JSON mapping to do a POST to an external API.  {"properties":{"objectType":"Customer","labels":[{"langue": "en","value" : "test"}]   => the underlined part is the list with 1 item with attributes value , language I tried this but it doesn’t seem to save the elementt(with l”language” & “value”) in the object LABELS. For now it only has to work a list with 1 item inside , later i can loop over it Thanks in advance , i hope it’s clear
asked
1 answers
3

Well, your JSON structure is invalid. I am not sure how you are creating this. The following would be the proper JSON structure to do this.

{
   "properties":[
      {
         "objectType":"Customer",
         "labels":[
            {
               "language":"en",
               "value":"test"
            }
         ]
      }
   ]
}
  1. Create one object Property and Create another object Label
  2. One property can have multiple Labels
  3. Property can have attribute “objectType” and Label can have attributes language and value

 

Thats mostly it. You can create import mapping with 2 ways.

Method 1:

  1. Create a JSON structure with the above snippet
  2. Use it for Export mapping, map the already created object or allow Mendix to create the objects for you, which is easier
  3. In a microflow, retrieve the Property entity, pass it to Export mapping, set the content type to JSON, save it in a variable and you will have JSON

 

Method 2:

  1. Create a Message definition with Property entity and select the attribute, Label association and its attributes
  2. You can have a custom name for export if you need
  3. Use Message definition to create Export mapping
  4. The in MF use the Export mapping to create JSON (same as explained above)

 

NOTE: if you are using the exact JSON as above and allow Mendix to create entities, you might get few entities that are not  relevant for you. But to keep the structure intact, Mendix helps you. If you got with method 2, you will get the JSON as you need except “{   "properties": “ and its relevant “}” bracket, which can also be handled with String concatenation. 

answered