Store local text variable ?

Store local text variable ?

  

Hi there,

I have a local variable of data type 'text' that I use to have the use fill in the value of.

I want to store this variable, so next time the app is started up, I can check if we already have it and if so, automatically move on to the next page without asking the user for it again.

I've created a new entity in local storage, but I cannot work out how to store the local variable there. Everything I try to use keeps telling me that the variable is text and I need to be storing a record. But, there seems to be no way to convert the text to be just a single record ?


Thanks,

Roy.

Hi Roy,

Your question above, and your previous question, lead me to believe you haven't followed all of the training material? Storing data in the database is pretty basic, and if you can't tell a Text from a Record, you perhaps need to revisit some of the more elementary topics.

That said, to add a record to a database Entity, you need to define a local variable of the Entity type, fill the right values, and use that as input to the Entity Action that will store the data in the database.

The variable needs to be a text as this is used elsewhere in my REST API calls as a text type to set a header in the API calls.. What I want to be able to do is to then store this text variable locally. 

From what I can see the only way of doing this is to create a Local Entity and store it as a record entry there. However, using the expression editor, it doesn't show any way to create a new record with the text value of a variable as an entry.

It would perhaps be simpler if outsystems just let you specify variables as being able to be stored in local storage rather than forcing everything to be a database.

We've evaluating this app just now and the next training courses in London are not for about 3 weeks. 

Solution

Hi Roy,

There's lots and lots of training material available. Please take the online courses first, as this forum is not intended to teach you the very basics.

As for your specific use case, yes, you will need to store any data you want to retain in the database. Although it would be nice to have some out-of-the-box persitant storage for configuration etc., it's just not there, and you need to store it yourself. The way to do it:

1) Create a Local Entity that can hold your value:

(of course, if you have more than one value add it as an Attribute, don't create a new Local Entity for every value).

2) After the user has set the value, store it in the Entity you just created. For this, you need a Local Variable of the type of the Entity you just created:

3) In the Screen Action that is triggered after the user has filled their value (e.g. by pressing a "Save" Button), assign the MyIntegerValue Local Variable that holds the value the user just typed to the MyIntegerValue of the Configuration Local Variable:

4) Call the Create Action of the Configuration Entity and specify the Configuration Local Variable as the Input Parameter:

And your done. In case this isn't a one-time action, but you want to be able to update as well, you need to read the current record first before assigning, and use a CreateOrUpdate instead of just a Create.

Solution

Thanks. I hadn't realised I had to create the record and assign the value in 2 steps to add it to the local storage record. I had assumed I could write values to fields in records directly as they were being created.

Hi Roy,

That would've indeed been nice, but not how things work :).

Roy Donaldson wrote:

Thanks. I hadn't realised I had to create the record and assign the value in 2 steps to add it to the local storage record. I had assumed I could write values to fields in records directly as they were being created.

Roy,

That is why Killian suggested the online training courses. That and other questions you had are easily answered there.


Abílio Matos