Hi,

how can I create a dynamic structure?

 for example from API I am getting 3 fields and creating a structure for three fields and using it in my page, what if in the future 2 more fields added to that API? again I should not go back to structure and add fields, I need to create fields dynamically in structure.

please, anyone can suggest how can I achieve this!

Hello,


What kind of API is it? REST, SOAP?

Regardless of it's type I would suggest looking through the documentation of the API for the maximum amount of Fields possible and build a structure with those in mind.


Regards

André Mavioso wrote:

Hello,


What kind of API is it? REST, SOAP?

Regardless of it's type I would suggest looking through the documentation of the API for the maximum amount of Fields possible and build a structure with those in mind.


Regards

Hi Andre,

I am using REST API


Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggested using HTML content right? but how can I achieve in  Out System


Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggest using HTML content right? but how can I achieve in  Out System


Since you've told us it's a REST API the response is in JSON. 

So you can receive the output of the API in text and interpret the JSON just like Frederico said.

Instead of the the brackets you are looking at something like this: 

{
  "attribute1" : "text1",
  "attribute2" : "text2",
}

That you can then apply logic to and extract the information that you need to a controlled structure.


If this is not helping at all, is there any way you can provide a sample.oml?



Hi Ronan,

You can't create dynamic structures - they always have a specific set of fields, selected at design time.

You can either account for the time needed to make changes in your application every time the service is changed, or you can implement Frederico's suggestion if you have control over the service or can discuss it with the provider. It's not HTML, but an actual list inside your structure.

Let's say the service returns something like this:

<Structure>

<Field1>ABC</Field1>

<Field2>DEF</Field2>

<Field3>GHI</Field3>

</Structure>

If you model this in Outsystems as is, you'll have a structure with three fields, and you can only add more at design time. But the data above can also be sent like this:

<Structure>

<List>

<Item>

<Code>Field1</Code>

<Value>ABC</Value>

</Item>

(etc...)

</List>

</Structure>

Datawise, these two structures contain the same data, but one of them can grow over time without any changes at design time, so long as your code can handle processing the data. I've implemented something like this last year at a client and while it is complex (you don't have a way to directly identify fields besides their codes), it is very rewarding to know that the structure can change and you won't have to do any changes.


André Mavioso wrote:

Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggest using HTML content right? but how can I achieve in  Out System


Since you've told us it's a REST API the response is in JSON. 

So you can receive the output of the API in text and interpret the JSON just like Frederico said.

Instead of the the brackets you are looking at something like this: 

{
  "attribute1" : "text1",
  "attribute2" : "text2",
}

That you can then apply logic to and extract the information that you need to a controlled structure.


If this is not helping at all, is there any way you can provide a sample.oml?



Hi,

Will try and let u know.

Thanks,

Ronan T


Ronan T wrote:

André Mavioso wrote:

Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggest using HTML content right? but how can I achieve in  Out System


Since you've told us it's a REST API the response is in JSON. 

So you can receive the output of the API in text and interpret the JSON just like Frederico said.

Instead of the the brackets you are looking at something like this: 

{
  "attribute1" : "text1",
  "attribute2" : "text2",
}

That you can then apply logic to and extract the information that you need to a controlled structure.


If this is not helping at all, is there any way you can provide a sample.oml?



Hi,

Will try and let u know.

Thanks,

Ronan T


Hi Ronan,


What Frederico proposed is a XML reply and the correct translation to JSON would be something like:

[

  { 

     "field": "<field name>",

    "value": "<field value>" 

  },

  { 

     "field": "<field name 2>",

     "value": "<field value 2>" 

  }

]

... basically an array of key+value pairs.


It's useful to have also an attribute with the "field type" (string, date, int, etc...) to know how to correctly handle the value.

 

This is something you may consider if you control the REST API side, if not, it's not a solution: your structure in outsystems needs to be a perfect fit with the reply and will not magically transform into a list of fields.

You may also consider handling the reply as text and unparse the reply manually using an extension.

Hope it helps.


Regards
Artur




 


Artur Resende wrote:

Ronan T wrote:

André Mavioso wrote:

Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggest using HTML content right? but how can I achieve in  Out System


Since you've told us it's a REST API the response is in JSON. 

So you can receive the output of the API in text and interpret the JSON just like Frederico said.

Instead of the the brackets you are looking at something like this: 

{
  "attribute1" : "text1",
  "attribute2" : "text2",
}

That you can then apply logic to and extract the information that you need to a controlled structure.


If this is not helping at all, is there any way you can provide a sample.oml?



Hi,

Will try and let u know.

Thanks,

Ronan T


Hi Ronan,


What Frederico proposed is a XML reply and the correct translation to JSON would be something like:

[

  { 

     "field": "<field name>",

    "value": "<field value>" 

  },

  { 

     "field": "<field name 2>",

     "value": "<field value 2>" 

  }

]

... basically an array of key+value pairs.


It's useful to have also an attribute with the "field type" (string, date, int, etc...) to know how to correctly handle the value.

 

This is something you may consider if you control the REST API side, if not, it's not a solution: your structure in outsystems needs to be a perfect fit with the reply and will not magically transform into a list of fields.

You may also consider handling the reply as text and unparse the reply manually using an extension.

Hope it helps.


Regards
Artur




 


Hi Artur,

thanks for your time, unparse the reply manually using an extension. which extension you are talking about?

and we don't have control over the Rest API side, is it possible to achieve?


Regards,

Ronan T


Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggested using HTML content right? but how can I achieve in  Out System


HI Ronan,

If you are using REST then your REST have to retrieve something like the JSON André Mavioso said, on the Outsystems side you have to do two strutures like the bellow: 


Best Regards,

Frederico

Ronan T wrote:

Artur Resende wrote:

Ronan T wrote:

André Mavioso wrote:

Ronan T wrote:

Frederico Fernandes wrote:

Hi Ronan,

It´s tricky... the only way I see is to create a structure that is a code/value List like this:


<Structure>

  <List>

        <Field></Field>

        <Value></Value>

  </List>

</Structure>


That way you just have to insert the fields and they values in the list.


Best Regards,

Frederico

Hi Frederico,

you suggest using HTML content right? but how can I achieve in  Out System


Since you've told us it's a REST API the response is in JSON. 

So you can receive the output of the API in text and interpret the JSON just like Frederico said.

Instead of the the brackets you are looking at something like this: 

{
  "attribute1" : "text1",
  "attribute2" : "text2",
}

That you can then apply logic to and extract the information that you need to a controlled structure.


If this is not helping at all, is there any way you can provide a sample.oml?



Hi,

Will try and let u know.

Thanks,

Ronan T


Hi Ronan,


What Frederico proposed is a XML reply and the correct translation to JSON would be something like:

[

  { 

     "field": "<field name>",

    "value": "<field value>" 

  },

  { 

     "field": "<field name 2>",

     "value": "<field value 2>" 

  }

]

... basically an array of key+value pairs.


It's useful to have also an attribute with the "field type" (string, date, int, etc...) to know how to correctly handle the value.

 

This is something you may consider if you control the REST API side, if not, it's not a solution: your structure in outsystems needs to be a perfect fit with the reply and will not magically transform into a list of fields.

You may also consider handling the reply as text and unparse the reply manually using an extension.

Hope it helps.


Regards
Artur




 


Hi Artur,

thanks for your time, unparse the reply manually using an extension. which extension you are talking about?

and we don't have control over the Rest API side, is it possible to achieve?


Regards,

Ronan T


Hi Ronan,


You can use ardoJSON to serializing and deserializing JSON. You can get it from the forge.

In this extension you have an action named "JSON_GetAttributes" described as "Gets a list of key/value pairs with the top-level properties of a JSON object.". It may be a perfect fit for you.


It has other actions that could be useful like:

'JSON_Listify': Replaces an object identified by Path with a list of name/value pairs.

'JSONSelect': Allows simple path selection of an element in the JSON.


When consuming the REST API just set the "Response Format" to "Plain Text" (instead of JSON) and the Response (Output parameter) to just Text (instead of a structure), and you will have your JSON as a string to use in ardoJSON.


Regards
Artur