append list
Question

Hey there , 

I'm starting learn OutSystems courses and I got problem to understand why we used list append and put the element to counter < rating as we defined this in IF condition.If anyone got a link or an article or a video describe how to make rating vote in a web please attached it it's will help to understand main idea .




Thanks 

mvp_badge
MVP
Solution

Hello Yousef,

Your first objective is to show to the users a list of stars (for example, 5), and the number of "filled" stars will tell the user the rating of the movie. So, if you have 3 filled stars in 5 stars (the last two are empty), you will tell the user that the movie has a rating of 3 in 5.

So, one option, the one adopted in the exercise, is to use a ListRecords. The source will be a list of booleans. And in the line template of the ListRecords, you use an IF to show an empty or a filled star. If the value in the current list item is TRUE, you show a filled star. If it is false, you show an empty star.

Now, you must build the list. So, your block receives a rating (the movie rating, for example, 3) and the maximum rating possible (like 5 in our example). What do you want? You want to fill your list with booleans, the first three with TRUE and the rest with FALSE so that your ListRecords in the screen shows the stars correctly.

As you must build the list, each value you want to add to the list must be appended to the end of the list using the ListAppend method. 

You do a looping using a counter, that starts in 1 (for example). If the counter is <= than the rating given, you put a TRUE (saying that the star to show at this position should be a filled one). When the counter goes beyond the rating, it starts putting FALSE (meaning an empty star). And the looping stops when the counter is bigger than the max rating.

Ex.

Rating: 3, Max Rating 5.

1. Counter = 1
2. Is Counter <= Max Rating? If so, go to 3, else go to 6
3. Append a new item to the List. The value will be Counter <= Rating. This is a comparison. If Counter is <= than the rating, it will return true, else, it will return false.
4. Increment Counter (Counter = Counter + 1)
5. Go to 2
6. Finish.

Hope this helps.

Cheers.

Eduardo Jauch wrote:

Hello Yousef,

Your first objective is to show to the users a list of stars (for example, 5), and the number of "filled" stars will tell the user the rating of the movie. So, if you have 3 filled stars in 5 stars (the last two are empty), you will tell the user that the movie has a rating of 3 in 5.

So, one option, the one adopted in the exercise, is to use a ListRecords. The source will be a list of booleans. And in the line template of the ListRecords, you use an IF to show an empty or a filled star. If the value in the current list item is TRUE, you show a filled star. If it is false, you show an empty star.

Now, you must build the list. So, your block receives a rating (the movie rating, for example, 3) and the maximum rating possible (like 5 in our example). What do you want? You want to fill your list with booleans, the first three with TRUE and the rest with FALSE so that your ListRecords in the screen shows the stars correctly.

As you must build the list, each value you want to add to the list must be appended to the end of the list using the ListAppend method. 

You do a looping using a counter, that starts in 1 (for example). If the counter is <= than the rating given, you put a TRUE (saying that the star to show at this position should be a filled one). When the counter goes beyond the rating, it starts putting FALSE (meaning an empty star). And the looping stops when the counter is bigger than the max rating.

Ex.

Rating: 3, Max Rating 5.

1. Counter = 1
2. Is Counter <= Max Rating? If so, go to 3, else go to 6
3. Append a new item to the List. The value will be Counter <= Rating. This is a comparison. If Counter is <= than the rating, it will return true, else, it will return false.
4. Increment Counter (Counter = Counter + 1)
5. Go to 2
6. Finish.

Hope this helps.

Cheers.


That's helps thank you very much.

Hi Yousef Ahmed,

You can check one live scenario here, where append list used multiple times.


Sravan

Hi Eduardo,

the logic is understood; what I still know not is - what is 'Element' under Action of ListAppend. The list is the boolen list, understood; but what is 'Element'?

mvp_badge
MVP

Hello, 

Element is what you want to append to the list. 

If the list is a Boolean list, you want to append Boolean values. 

So, you need to provide a Boolean value, true or false, to the element property of the ListAppend action. 

Element is just what you want to add to the end of the list. 

Thank you Eduardo.

The 'Element' property is just not self-explanatory. Now I see that Element is like the row-cell in the list and the value entered is what is stored in that row-cell.

Furthermore, just entering 'counter < rating' is not self-explanatory that the result of that Boolean condition is to be stored in the element-row. (I kept thinking why is a condition entered for a value there).

Well, now i get it.

Thank you much for your help.

mvp_badge
MVP

Hi David, 

I understand and I agree that the name used for this parameter may not be the most common or intuitive. 

Just be careful that a condition is an expression with a result (true or false). 

It is usually used as an IF condition, but we can use a comparison and store the result of the comparison in a variable, or passing as argument to an action, like in this case. 


Cheers 

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