How to remove duplicated records ( displayed on screen)?

Hello!

I've got a problem. The records from the database are being displayed on screen. 

they're not duplicated in the database. just when displayed. 


Does anybody know how to solve this?

Hi 

In the aggregate you can group by one selected attribute, like a primary key (ID), this way you you will get distinct values. But it is important to understand why this is happen, probably some bad join.

I hope it helps :)



Likely a problem in your joins in the aggregate. Can you show what it looks like?

Juan Carlos Elorde wrote:

Likely a problem in your joins in the aggregate. Can you show what it looks like?

Follow the image of joins. 


Is the DepartmentId a SectorId ?

EFreitas wrote:

Is the DepartmentId a SectorId ?


Yes. it is!

What are the attributes that you want to show in the screen?

Did you already tried the group by solution?

Hi Raissa,

If I understood your problem, I propose you this solutions:

  • The SortRecordList Extension is your best bet. Use ToObject() around your List.


  • Other solution, the first is to use a single SQL query, using the UNION command, something like:

SELECT ...

UNION

SELECT

Doing this removes the duplicates at the query level, and SQL Server will do the job for you.


  • The other way to remove duplicates is to do use a For Each loop to check if the items in the second SQL Query already exist on the first on one by one, and only append the ones that don't. Note that this will require a For Each loop inside a For Each loop so it not only will look a bit messy, it will also not scale very well.


I hope this help you.

Cheers,

Nuno Verdasca

EFreitas wrote:

What are the attributes that you want to show in the screen?

Did you already tried the group by solution?


I wanna show the sectors (in a list) and the annoucements of each sector,  but they're look duplicated.

If you use the group by, int the DepartamentId attribute, may will work well, but which elements you want display in the screen?

If you want to show more than one announcements for each sector, you can achieve that by the following:

First create your sectors list.

Second, create an Block that shows the list of annoucements by sector Id.

At the end use that block in the first screen.

You can use this function too:

Raissa Domingos wrote:

EFreitas wrote:

What are the attributes that you want to show in the screen?

Did you already tried the group by solution?


I wanna show the sectors (in a list) and the annoucements of each sector,  but they're look duplicated.

In this case, i think the solution above is the better to display the elements.

if you prefer, you can work with a list variable with a structure that you need to display in the screen, and at the preparation pass the records to list variable, removing the duplicateds, and use this variable like a source to list widget on the screen.


Leonardo Nascimento wrote:

If you use the group by, int the DepartamentId attribute, may will work well, but which elements you want display in the screen?

It's not working. When I tried 12 error messages appear, and I don't even know how to solve, cause the logig used  used is not mine, and i'm an outsystems newbie 



Raissa Domingos wrote:

Leonardo Nascimento wrote:

If you use the group by, int the DepartamentId attribute, may will work well, but which elements you want display in the screen?

It's not working. When I tried 12 error messages appear, and I don't even know how to solve, cause the logig used  used is not mine, and i'm an outsystems newbie 



Raissa, try the Distinct function, that I show you. When you pass the list as SourceList, it returns you a list without the duplicates. I think this is what you are looking for.

Cheers,

Nuno Verdasca


EFreitas wrote:

If you want to show more than one announcements for each sector, you can achieve that by the following:

First create your sectors list.

Second, create an Block that shows the list of annoucements by sector Id.

At the end use that block in the first screen.

the annoucements are being displayed. but the sectors are stil duplicated. Do you think that could be some relationship that is missing or wrong?


Nuno Miguel Verdasca wrote:

Raissa Domingos wrote:

Leonardo Nascimento wrote:

If you use the group by, int the DepartamentId attribute, may will work well, but which elements you want display in the screen?

It's not working. When I tried 12 error messages appear, and I don't even know how to solve, cause the logig used  used is not mine, and i'm an outsystems newbie 



Raissa, try the Distinct function, that I show you. When you pass the list as SourceList, it returns you a list without the duplicates. I think this is what you are looking for.

Cheers,

Nuno Verdasca



I'm gonna try Nuno! Hope it works! Thank you

Raissa Domingos wrote:

Leonardo Nascimento wrote:

If you use the group by, int the DepartamentId attribute, may will work well, but which elements you want display in the screen?

It's not working. When I tried 12 error messages appear, and I don't even know how to solve, cause the logig used  used is not mine, and i'm an outsystems newbie 



Which the attributes you need to display in the screen?

that I show you

Before:


After


I had two MIGUEL and one Miguel, and I only had one of each. I know this is a simple example, but it works.

Cheers,
Nuno Verdasca

Raissa Domingos wrote:

EFreitas wrote:

If you want to show more than one announcements for each sector, you can achieve that by the following:

First create your sectors list.

Second, create an Block that shows the list of annoucements by sector Id.

At the end use that block in the first screen.

the annoucements are being displayed. but the sectors are stil duplicated. Do you think that could be some relationship that is missing or wrong?


You need to remove News entity from the aggregate. You only need to get the Sector list


Solution

Raissa Domingos wrote:

Juan Carlos Elorde wrote:

Likely a problem in your joins in the aggregate. Can you show what it looks like?

Follow the image of joins. 


You already have a Sector.FunctionalAreaId already. I am just thinking why you also have a cross join for FunctionalAreaXSector. There could just be a wrong relationship on this that is why it duplicates. What you can do is isolate your entities. Meaning, add entities as you need them. 


EFreitas wrote:

Raissa Domingos wrote:

EFreitas wrote:

If you want to show more than one announcements for each sector, you can achieve that by the following:

First create your sectors list.

Second, create an Block that shows the list of annoucements by sector Id.

At the end use that block in the first screen.

the annoucements are being displayed. but the sectors are stil duplicated. Do you think that could be some relationship that is missing or wrong?


You need to remove News entity from the aggregate. You only need to get the Sector list


As EFreitas said, you may need to remove some of the entities you don't need because this may be the cause of the duplicates.


Solution

Juan Carlos

That cross join for FunctionalAreaXSector. It wasn't made by me. There's other people working on the same module of the aplication. And it's true, that's the cause of the duplicates. Thank you so much for the help!!