Model and Query Data
Create and Use a Look-up Table
This lesson is part of the Developer Online Class for OutSystems 9 course.

in this lesson we will use a static entity to define the possible statuses
of an Order so let's go ahead and create here in new entity
and this will be a static entity and we will call it Status
a static entity is an entity whose date the stored in the database
just like other entities but its records
are managed in design time only since it is an entity
you can use it in aggregates so this means that we have this
entity that its data is stored in the database
but we have to define its records here
in the development environment let's go ahead and define the status of the
so we'll have the new, the shipped
and the canceled status just like other entities
a static entity has attributes that
define the data these records hold
in this case we have a label, an order attributes and
an Is_Active attribute for each one
are these records we just created let's add the Status
entity to the diagram here and
as I said we want to specified the possible statuses
of an Order so this means that we have to create the relationship between the
Status entity
and the Order entity and
we will do this again by adding a new attribute to the Order
which will be a StatusId
okay so we have changed the Order entity so
let's go back here into the screens and well the first thing I want you
to notice is that
despite we have changed the Order
entity all the screens... you'll notice that
we are good to go to publish the eSpace so all the screens that
use the are the entity namely the order screen and the order detail
they still work
and basically they work because the platform
the platform optimizes these elements that we have here these
aggregates by only fetching from the database
only fetching from the database the data that it needs to render
to render the screen so if we want to show here the StatusId
then we would have to go here into the aggregate
let's just do that add
the status label
here and this creates
another join condition between the Order
and the Status and here on the table
we can show now
the status label as well
we can either drag and drop this label or we can
drag and drop the foreign key because as you seen before
the platform will replace this foreign key
we'd the status label here
on the table records okay so
Order is changed let's take a look into the OrderDetail
in case of the OrderDetail we will need to change here the form so that we can
edit the status of an order so again let's go here into the Data tab
drag and drop the StatusId after the Detail
and and now I want to do one more thing because
you'll notice that now that we have a status we know
we know that we can condition here this logic to add
items only only when the status of the Order
is new so this means that well first of all let me go here
into the aggregate and and usually you do this
you need to go here into the GetOrderById
add the Status so add the Status entity here
and now here on the screen
you want to test here in this link
want to make this link only visible we want to render
this link only and we will do this
with this visible property only when the status of an order
only when the status of an order is new
and usually you would do this this way
check the label to be cool
to New but actually this is this is not the best way
to do this because actually we can go here
into the Status and say that the label
of the New record is now
New Order and this means
that this validation here would no longer work
one of the advantages of using static entities is that you can directly
a single record in the logic of your application
and avoid using these hardcoded values that are error prone
so in this case what we actually want to do is to validate
that the order
status is equal
to this particular record to the new records
despite the label that this record has
and to test this condition we have
here the possibility
to directly reference this New record
in our logic and this makes this test
valid whatever the label
we decide to define for this status
okay so this is this is OK let's move on to
do the same do the same thing for the Delete
button so the Delete or the delete link the delete link
is only visible if our
order so let's test here
that our order status
is equal to you can use here the auto complete Entities
dot Status tab
dot New there
okay so we're good to go let's publish and test these changes to our application
okay let's go into... we don't have still s status for our
order let's enter our order
and as you notice since we don't have a status we don't have the link to
delete and we don't have the link to add a product so let's
change this to New Order and Save
and there we have it. Now we can add or delete
items to our order let's try to add a new
item let's say that we want a mouse here
and it's working and now we can change to
Shipped and those buttons
are removed those links are removed from
from the user interface and that's it