68
Views
14
Comments
Error when selecting dropdown tags option?

In my site I am using a DropdownTags widget and its function is to show the categories of the products. The error is that when I choose more than one category, it stays with the lowest id_category. As an example I have 3 categories and I choose the 1 and 2, it only shows me the 1.
How could I select more than one category and show me all the products that are assigned to the selected categories? I do not know how to solve it, please help me a lot. 


  

Here I select the first one and at the top you can see the idcategory



here I select the second one and I get the message of the selected id 2


here I select the two and here is the failure when I choose two it shows me the id of the lower categories


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

Hi Roman,

I'm not sure how you are constructing that message, so can't be sure, but it looks to me like 12 is both 1 and 2 ??  So nothing wrong there, the selection gets sent correctly into the action.

So are you talking about what your code does with this selection ?  Please share that, for example, if your logic is something like refreshing the product list, then show us how you are talking into account both selections in that logic ? 

 If you update some 'current category' local (a list ?), and then you just have an aggregate that filters on that 'current' categorie, or something like that, that can't work if more than 1 category are selected, it will always give you either the first or last one selected.

You'll probably need an sql widget with an IN clause, or alternatively some sort of low code variation of using an aggregate to get all, and than filter out category afterwards, which really only is an (ugly) option if there is not a lot of data.

Dorine

UserImage.jpg
Roman Monge

The 1-2 is from a previous version I made a mistake. This is the correct screenshot, the other two are fine.

Lo que estoy buscando es que me muestre los productos que tienen las dos categorias asignadas y lo unico que consigo es que me muestre el producto con la id categoria mas pequeña.

This capture is the action of the dropdown. Here the filter that I use in the aggregates, databases CategoriaProducto, Producto.

2021-09-06 15-09-53
Dorine Boudry
 
MVP
  • For starters, I don't think you fully understand the dropdown tags pattern
    • your event will have a list coming in
    • this is the full selection of categories at time of event, so all the information you need is right there
    • it looks like you are referring to the list that is the source of your dropdown (named 'list' ?)  that is useless, the list.current just refers to the first record in that list (unless inside/after iterations), has no relation to what the user is selecting
    • so you will probably need an extra local variable list 'selectedCategories, that you copy from the input list of your changed event
  • it is completely unclear what you are doing with all the stringsplit and such
    • you are looking at the length of the 'current' item in the list ?
    • what do the f and t mean ?
    • what are you doing in that stringsplit ?
  • and in the place where it matters, your aggregate, you are also not doing anything with the selected list, only with the first element of the source list (a.f.a.i.k.)

Unfortunately, a simple aggregate has not good/easy support for filtering on a list of values. 

For how to solve this, see for example this post.

Dorine

UserImage.jpg
Roman Monge


this part I don't know how to do it " it looks like you are referring to the list that is the source of your dropdown (named 'list' ?) that is useless, the list.current just refers to the first record in that list (unless inside/after iterations), has no relation to what the user is selecting"  
In the first part you refer to the filter? because I don't know how to compare all the elements of a list in a filter. Also the list you selectedCategories what type is it?
        you are looking at the length of the 'current' item in the list ?
 If it was necessary it gave me a failure
        what do the f and t mean ?
 To check if it fits or not
        what are you doing in that stringsplit ? I have removed it


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


because I don't know how to compare all the elements of a list in a filter.

see that link i shared

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


Also the list selectedCategories what type is it?

i would make that a list of categoryId, so in the OnChange of your dropdowntags, just clear it, append all from the input if the event (which is a list of DropDown Item) and convert item value to identifier.

Then you have a list of identifiers of category, how you should use that in your aggregate, see that link I shared 

UserImage.jpg
Roman Monge


sorry I don't understand, just clear it, append all from the input if the event (which is a list of DropDown Item) and convert item value to identifier. I am also looking at the link you gave me

UserImage.jpg
Roman Monge


and the filter is correct or do you recommend me to change something?

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

nope, the filter is not correct, see example in other link

why don't you share your oml, and I'll have a look

UserImage.jpg
Roman Monge

The projectPc is the file with the dropdown and the cs with the database.

ProjectPc.zip
ProjectPc_cs.oml
UserImage.jpg
Roman Monge
2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi Roman,

i am looking at your oml.

So in the DropdownTagsOnChange event, it feels like you are doing way too much, all you really need to do is 

  • make sure you have some sort of local variable holding the list of selected categories
  • transform this into some sort of form that can be used in your aggregate or sql
  • refresh your aggregate

so that local list you used before (called 'list', maybe rename it to 'SelectedCategories') is fine, I was thinking about making a list of category id's, but this should work too (dependent on your choice of what to do, even better to leave it as text).

Now, for the real problem : you have to take into account in your query (either aggregate or sql widget) all the selected categories.  The typical way to do this is with an IN clause, but unfortunately, Outsystems aggregates don't support that.

That other post I pointed you to, has an oml comparing some options, including the sql, but also some variations with an aggregate.  Again, go study it, you'll have to choose one of the options of how to do this.  You will see there, that I also used a list of DropdownItem, so forget my remark about making a list of id's.

Dorine

2023-04-18 10-31-31
Anshul Jain

Hi Roman

If I understand correctly you want to select multiple options from the dropdown and want to filter the aggregate data based on the option(s) selected via the dropdown.

If that's the case I would recommend you use String_Join in DropdownTagsOnChange action. Create a local variable to store the result of the String_Join output and to use in the filter of the aggregate.

Here I have used a comma as a separator and then I have stored the output of the String_Join in a local variable of text type (in the assign below the String_Join)

After that, you can use the local var in the aggregate filter like this

This will help you filter the aggregate based on multiple selected Ids like this


Hope this helps

Thanks,

Anshul

UserImage.jpg
Roman Monge

Thank you very much Anshul Jain

The problem is that if I select 1 product that is assigned to 2 categories, it shows it twice. 




And what I would like is that it only shows me the products that are assigned to those id, I mean if I select two categories that shows me the products that are assigned to that category. But anyway thank you very much for the help

Roman 

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