Sort dynamicValuesExpression Display (dynamicEnum, dynamicCheckbox)
Hi there,
I’m trying to create a dynamic map of ~2000 assets for display on a form as part of a dynamicEnum, and I’m having issues with sorting them alphabetically.
When I create a HashMap<String, String>, it will work, but the sorting will be off. My map appears to be sorted correctly, but when actually displaying on a workflow form using a dynamicValuesExpression, the order is all over the place.
I dug into it a little and I can sort of make it sort based on the key if I assign them as single characters. It will sort 1-9, A-Z and then a-z. I guess based on the char value? This didn’t really seem like an optimal solution for several thousand assets though.
Then I thought, well, if I make my HashMap<Integer, String> that would work nicely. It does seem to build the map okay as you would expect, but I’m running into an “Integer cannot be cast to String” error when I’m trying to display it on the form. That is, the script task will end successfully, but the wf will crash when the form task tries to open.
Has anyone figured this out? Am I doing something wrong? Is this a Collibra limitation? Is there a workaround?
Many thanks
arthurburkhardt
·4 years ago · EditedHaven’t tried it myself, but did you try creating numbered string sequence?
0001
0002
0003
…and so on
arthurburkhardt
·4 years ago · EditedHaven’t tried it myself, but did you try creating numbered string sequence?
0001
0002
0003
…and so on
danielcousins
OP4 years ago · EditedHey Arthur,
Thanks for your reply. I will investigate a solution with the above method as well, but I did actually find an easier workaround for us that essentially dropped right in.
Just in case anyone else finds this and is curious, if you use a HashMap, order of insertion will not be preserved, however, if you use a LinkedHashMap instead you can preserve the order of the map.
That way, as long as you sort the list first, and then feed it into the linked map in that order, it should come out right on the other side.
I also investigated using a TreeMap instead which automatically sorted the values for me.
I’m not sure how I ended up assuming that these maps had to be HashMaps, but that was the crux of my issue.