20
Views
6
Comments
Solved
How to map a Boolean variable to an integer without losing the old data?
Application Type
Reactive
Service Studio Version
11.54.31 (Build 62912)
Platform Version
11.23.1 (Build 40847)

Hello, OutSystem community, 
I have an application to collect some Agreements data, and one of the fields is the Status.
What I have now on production is statuses (Active and Closed)
And for that, I created the variable Status that it's a Boolean.

True: Active

False: Closed
(I was using a radio group button for the Status.)

But now, I need to have 2 more new status (Active, Planned, Closed, Canceled), so I created a new variable that it's an Integer.

(I'm now using, for the agreement status, a Button Group)

How can I kind of "map" the Boolean values to Integer without modifying/losing the old data?
I mean, every Agreement was set to "True: Active" when I moved the code from the dev environment to the test environment and some of them had already been changed to False (the user manually changed). So, considering that the other environment doesn't have this new Entity Attribute (agreement_status), if I just simply move things to the other environment, everything will be set to Planned (default value) and I will be losing the old status, right?

> So, what I basically need is:
 I need to assign the right values to the Button group, so if the agreement already exists and have the "Status" as "True: Active" I need to assign the value of the "agreement_status" to 2 (active) in the Button group and if it's "False: Closed", it needs to get the number 4, that represents the closed status in the button group. 

How can I create this mapping action? I mean, the default value for the "agreement_status" is already Planned, so if the person is creating a new Agreement the default option will be Planned, but how and when I map the agreements that already exist? 

And I don't really know if it's an action what I need, because I just need to make this mapping one time, right? Focusing in don't losing the old data for the default value of the new variable.


I'm really lost, so I really appreciate any tips and help with this.
Thank you so much!

Solution

Step 1 create new column in your entity it’s type is integer to store status 

Step2 : in dev you use newly created column to manage status 

Step 3 : for next deployment create a timer which gets current status and write that status to newly created column 

Eg : if current status in the production True , for that record insert 1 in newly created column 


NB: insert only if newly created column has no value or default value - 

Do not set timer run on publish - just in case you forget to remove timer in next deployment - it is not gonna change the current values unless you run the timer manually again 

Hope it work 

Hello Jamal, thank you for the help!
I just have one question, if I'm not setting the time to run when I publish, how can I implement it in a way that it will run and remap the values?

The Idea is basically this, right?
I'm checking if it's true and false and setting the values, and if it's none of them I just skip the process (All of them right now should have at least one of the true/false selected)

Solution

You can create a timer and at that timer, you are going to get the data (you can do the filter of the ones who have true or false, up to you) and do the right mapping to the new attribute. When deploying the changes to the test environment you just need to run the timer. And it will do what you want without losing data. But you need to create a new attribute and use the old attribute to do the mapping on the timer, That way you will not lose the data you had before.

Hello Márcio!
Thank you so much for the help :)
I just have one last question, Jamal said that I shouldn't set the timer to run when published in case I forget to remove it, so how can I make it?
I mean, the ideal it's to run this action for the first time them remove it? (What are the good practices to this hole process?)

The timer action that I created:

Again,
Thank you!! 

When I do those kinds of timers I put a time in the schedule time, you can make it daily and make it run at some time am or even choose a day of the month to run to give you time to do another deployment. And when you feel you do not need any more of the time and everything passed the smoke tests you remove the timer :) And then you can deactivate your timer if you don't need it any more before doing the deployment with the timer removed.

Solution

Step 1 create new column in your entity it’s type is integer to store status 

Step2 : in dev you use newly created column to manage status 

Step 3 : for next deployment create a timer which gets current status and write that status to newly created column 

Eg : if current status in the production True , for that record insert 1 in newly created column 


NB: insert only if newly created column has no value or default value - 

Do not set timer run on publish - just in case you forget to remove timer in next deployment - it is not gonna change the current values unless you run the timer manually again 

Hope it work 

Hello Jamal, thank you for the help!
I just have one question, if I'm not setting the time to run when I publish, how can I implement it in a way that it will run and remap the values?

The Idea is basically this, right?
I'm checking if it's true and false and setting the values, and if it's none of them I just skip the process (All of them right now should have at least one of the true/false selected)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.