161
Views
7
Comments
Aggregate into Structure

Is there a way to parse all the attributes from an aggregate into a structure so you can use the structure on a different screen?

I have the user select checkboxes that align to records in a table and i want to parse all the records that have a true value in these booleans to a structure so i can use these records in another screen. How would i go about doing this?

PS new to outsystems

mvp_badge
MVP
Rank: #18

Hi Mitchel,

Yes you can map data from an aggregate to a structure, and OutSystems helps you with that.

If you have a structure of just atributes you can map one particular record, most likely the current to a structure.

If you have a list structure you can map the complete aggregate list to the list structure. 

You map data by assigning the aggregate record or list to a structure or structure list using the assign widget

OutSystems will try to automatically map all the atributes. Where OutSystems cannot map them automatically you can set the mapping with optional transformation yourself.

Regards,

Daniel


Rank: #27270

Hi Daniel, 

thanks for the reply. when you assign an aggregate list to a structure, would this be be a server action, a data action or a client action? all options at the moment seem to not allow the input of structures into the logic, even in the assign widget. 

thanks again 

mvp_badge
MVP
Rank: #18

Hi Mitchell,

The mapping of attributes is done using an assign widget, this is possible client side for only mobile and reactive applications as well as server side for all application types.

Why you think it is not possible? The mapping of data is actually a strong feature of OutSystems.

Regards,I 

Daniel

mvp_badge
MVP
Rank: #18

Hi Mitchell,

Where you able to solve your problem?

Regards,

Daniel

mvp_badge
MVP
Rank: #18

Hi Mitchell,

I had a look at your code, but saw things that do not make sense to me:

This screen fetches data from the database using 4 aggregates, every time from the Course and/or Major entity, this seems to be very inefficient.

On two of them (Major2Directed and Major1Directed) you defined an OnAfterFetch event handler called deJsonForM1M2Dir. For Major2Directed OutSystems reports the following warning:

Potential Loop at runtime

Refreshing ''Major2Directed' Aggregate' in 'On After Fetch' triggers the on after fetch event again. To avoid an infinite loop, remove the refresh of ''Major2Directed' Aggregate' from 'On After Fetch'.

Then looking at the logic you implemented in deJsonForM1M2Dir:

First thing you do is clearing the results form the data retrieved and available in the aggregates Major1Direccted.List and Major2DirectedList. This makes not sense. I figure you either ou tried to define to lists as local variables but didn't know to. To create the two lists (Not aggregates) do this:

  1. Add a local variable can name it CourseList, you will see OutSystems will automatically set the data type correctly to CourseList.
  2. Now rename CourseList to Major1DirectedList.
  3. Copy paste Major1DirectedList and rename it to Major2DirectedList.

Regarding the automatic mapping, this will only work at its best, if attribute names and the data types between entities and aggregates are the same, in your Course entity you start your attributes with lowercase and semester and yearLevel are of data type Integer. and in:

And in your structures with uppercase, and Semester and YearLevel are of data type Long Integer.

If OutSystems does not automatically map the attributes you can still easily do this your self by selecting the proper attribute from the response structure from the JSONDeserialize action.

Another note I have on the datamodel:


As you see you didn't define proper foreign keys in  Degree, Major entity to the Course entity.

coreCourseId and directedCourseId should by of data type CourseId.

Also DegreeIdentifier is not of data type DegreeId

And I doubt you need it because the last attribute in the entity is already DegreeId

Given the relation between Degree and Major, why do both entities have the attribute coreCourseId and directedCourseId?

To create the screen that you try to make I think you do not need to resort mapping your aggregate data to list structures just for display. You have to fix your data model, ensure the proper relationships between the entities are defined, redundant attributes are removed. This will enable you to create the proper aggregates to select and show the database data on the screen.

All in all, taken in consideration that you are fairly new to OutSystems I would advice you to first invest some time to learn the basics of OutSystems. The https://www.outsystems.com/learn/paths/ site has great free learning material. It is worth while the investment (I know, I did).

Regards,

Daniel