Create a Structure/Entity from string

Is it possible in outsystems to create a structure or entity dynamnically based on a string which has the class attribute names in C# like this:
 

I don't think that exists, but you can create a structure from a json string.

Hi Mohamed,

You can't define Entities or Structures at run-time, only at design-time. Could you tell us a bit more about your use case? Maybe there is another way to achieve what you need.

Stefano Valente wrote:

I don't think that exists, but you can create a structure from a json string.


Is this possible at the run-time?

No, it's not. Outsystems stores everything in systems tables before publishing and deploying. You could say publishing is the same as compiling. So its not possible to add structures at runtime.


What is it exactly you are trying to achieve? Low code generally means you have to think different but most things are possible to achieve.

The scenario is executing a different SQL Query that I don't know so basically I need a structure with the same columns, data types, etc to have the output of the Advanced Query presented, so I thought maybe I can get this as JSON String, then I can create structure from that JSON, but it should at the run-time as the user of the appliaction will write an SQL Query that I don't know, so the structure output should be generated right after the execution of the user's query!

its not impossible.

Let's say you will receive a string containing a SQL statement. You can rewrite the statement so the output will be 1 string. This means you can use a structure with 1 textcolumn.


How were you planning on showing the information?

Stefano Valente wrote:

its not impossible.

Let's say you will receive a string containing a SQL statement. You can rewrite the statement so the output will be 1 string. This means you can use a structure with 1 textcolumn.


How were you planning on showing the information?

like for example: Select * from {User}

I want to show the output of this query in a table or a list with all columns as the user wanted, or only the selected columns if the user want to select only few columns!


Hi Mohamed,

You should completely forget about this, this is not how OutSystems works. Design time, all Structures and their Attributes must be known, there is no way to anything dynamic like that. If that is something you really need, OutSystems is just not the product to use.

Stefano Valente wrote:

i haven't tried it myself, but check this one:

https://www.outsystems.com/forge/component-overview/4424/dynamic-sql-query-screen


I tied this before, but the problem is it doesn't work with external databases, I guess!


so it normally retruns the espace name, and then list the entitites available, and then query them, but I have external database, so I have an extension in my espace, but the tables in this extension are not visible in that espace, so is there a way to solve this! or maybe I am missing something!


as you can see the last record is one of the entities of my external DB and it has Espace id of 0!



As Kilian said: the only problem you have is not knowing your structure. If you can find a way around this (is it really necessary to make your options that generic?) then its possible. If not, Outsystems might not be the best choice for this problem.


The scenario is executing a different SQL Query that I don't know so basically I need a structure with the same columns, data types, etc to have the output of the Advanced Query presented, so I thought maybe I can get this as JSON String, then I can create structure from that JSON, but it should at the run-time as the user of the appliaction will write an SQL Query that I don't know, so the structure output should be generated right after the execution of the user's query!

I'm not sure of how much freedom you're planning on giving the user writing the query, it sounds like a dangerous opening in your application. 

But your reasoning sounds correct: you could have your dynamic SQL query return a JSON string (so just one structure with a String field) and then have a JS function output it into a dynamic table: you wouldn't have to be aware of the structure output at design time since everything would be dynamic.

I see your points, I am also trying to think out of the box to find a reliable solution to it!


I have another question that might be releveant! Is it possible to get the logical database name at run-time?

someone already gave me this comment before: 


/* %LogicalDatabase%=GetLogicalDatabase({COUNTRY}) */

to add in my Advanced Query to let Outsystems know exactly which database I am trying to query, and this works but only inside the Advanced Query, so is this possible to have as a function and save it in a variable or something?