Hi,

I am trying to create a "add to compare" feature in my native app. Users will be able to add an item into a "Comparison" page. 

However, i faced some problems while trying to create this feature:

1) The creation of data in the "Add to compare" entity. I tried assigning the values as shown in my attached oml, but it does not seem to be working. 

2) The display of the data in my "Add To Compare" page. The idea is that at any one point, there will only be 2 data in the "add to compare" database. I tried the method as suggested in my other forum topic https://www.outsystems.com/forums/discussion/59317/side-by-side-comparison/#Post226227, to show both the data in the database. However, the error of "Index out of bounds. Index 5 for empty list." appeared whenever i tried to access the "Add To Compare" page. 


Hi Jolene, 

I think the attachment of the OML failed. I don't see it.

Kind regards,

Vincent Koning

Vincent Koning wrote:

Hi Jolene, 

I think the attachment of the OML failed. I don't see it.

Kind regards,

Vincent Koning

Hi Vincent,

I have edited my post and added the attachment. 


Hello Jolene.

In your screen to show the elements to compare, you are accessing the list output of the aggregate, from the screen, using the Index. 

You are doing something like this in the expression:

SyntaxEditor Code Snippet

If(GetAddToCompares.List[5].AddToCompare.Colour <> NullTextIdentifier(), GetAddToCompares.List[1].AddToCompare.Colour, "")

Do you realize that you are saying that you want to compare an attribute of the 6th element of the list, but there is no guarantee that you have 6 elements on it? the [index] subscriptor will return the row of the list indicated by the value index.

So, your data model will not work as expected, in any situation.

Suggestion (from top of my head, without thinking, so probably not the best idea...). 

Use two client variables with data type ItemId (Item Identifier) to store the IDs of the items you want to compare.
e.g. ItemId1 and ItemId2

In the screen where you want to see the comparison, set an aggregate to fetch from the Item entity, with the following  filter: 

Item.Id = ItemId1 or Item.Id = ItemId2

Then, use a LIST to show the two records, or validate that you have two IDs before showing the information (as you will guarantee that both rows 0 and 1 will exist and no error when accessing).

Cheers.

Solution

Hi Jolene Kwek,

In support to Eduardo Sir solution comment, I tried to create a small sample app as per the mentioned requirement.


Check this: Sample App

PFA - Includes solution .oml


Hope this helps you!


Regards,

Benjith Sam

Solution

Well done, Benjith. Thank you :)

Eduardo Jauch wrote:

Well done, Benjith. Thank you :)

You are welcome Sir :)


Regards,

Benjith Sam

Hi Eduardo and Benjith, 

Thank you so much for helping! 

Jolene Kwek wrote:

Hi Eduardo and Benjith, 

Thank you so much for helping! 

You are welcome :)

Glad I could be of help!


Regards,

Benjith Sam