34
Views
3
Comments
Split row into multiple rows based on column values
Application Type
Reactive

Hi everyone, I'm quite a beginner with OutSystems and had a question about the best design approach for a form I am building.

I want to have a form with user inputs but I want to save the data dynamically according to the input values.

For example,

I already have an Entity which kinda looks like this (saves data from the form):


URL1          URL2          URL3         URL1_Click          URL2_Click         URL3_Click          Cost          Impressions

abc.com   xyz.com                                 10                      15                                                    10                     50


From this entity row, I want to create a record/row or new rows in a new entity that splits up the row based on the number of URLs available and also divides the cost and impressions by the number of URLs provided. Since I have 2 values in the URL, it split it into 2 rows. If it was 3, it should split it into 3 rows and also divide the cost and impressions by 3.

So, the new entity record should look like this:

URL                   Click          Cost          Impressions

abc.com             10                5                    25

xyz.com              15                5                    25


What should be the best approach to tackle this problem?

The OML I created is just the form and the entity; thus, it was not uploaded here.


Thank you very much!

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Since you are asking in an OutSystems forum :

you can just write logic in an OutSystems action to do this. You already decided on the specs, so you can just retrieve all rows in the existing entity, and add 1, 2 or 3 records in the new entity, and calculate the numbers as described.

you can put this in a timer, and if you have many records to handle, make sure the timer is restartable by removing the records in the original entity (either hard or soft) once they have been processed into the second entity.

But alternatively, if you have access, you could just use some sql tool and do it directly in the database.

Dorine

2024-12-18 16-06-42
Junaid Syed

I think you need to write custom logic which I will come to in a bit, before that to maintain data integrity in your application please add a foreign key to form entity record in your entity storing them in rows format.

Here is the pseudo code

1. Pick the records from form entry entity which have not been processed yet, probably you could identify unprocessed records using the join between two entities using the foreign key relationship mentioned above.

2. Pick one record at a time, read the URL columns which have values.

3. For each URL column with value, pick the values from associated columns.

4. Store the values including calculated ones in the row entity record.

5. Insert a new record in the row entity.

Hope it helps

Junaid


UserImage.jpg
Rounak Rawat

Hii @Mishkat Nur Rahman ,

I attached a oml file for take a reference.

regards,

Rounak Rawat

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