I'm trying to fix a bit of code where whenever a user adds an item in a list, if a similar item exist, it would not be added into the list and the user would be notified as such. I've made this sample block, it can add items but if it finds an item similar, it crashes the whole app.
Can anyone see the mistake here?
there is a block to check if a list contains a item.
use that block.
this is from Text. pls find in List. 'IS IN LIST'
It still didn't work. At least it doesn't crashes, but now it still wont stop adding duplicate items into the list
you are doing like this:
If list a not contains item b then add item c to list a.
1 Like
ABG
March 10, 2023, 11:47am
7
If you want unique items, use a dictionary instead of List with name as key .
A TinyDB would be persistent, even better.
Regenerate your Element list from the patient store in a separate reusable procedure.
I'm not very well versed in using the Dictionary blocks, can I get some help with that?
ABG
March 10, 2023, 2:38pm
9
ABG
March 10, 2023, 2:43pm
10
For your patient data example, what would you do if some one mis-spelled their name slightly?
Would you start a new patent record?
Instead of an exact match and unique names, consider the Google Sheet component, which has a block to search for partial matches.
I tried Dictionary as it was much more simpler for me personally, but now whenever I add a new element, it comes up like this
Here is the block for adding
And I also cant delete stuff anymore.
Can anyone tell me what I've done wrong here?
you need save your data as simple as possible.
and is there any relationship between your dictionary and the listview?
The data would be saved in the dictionary while the listviewer shows what's inside it.I want the Patient_name to be the maintext and the rest as detailtext for every element in the listviewer
Angelo_Cawas:
what's inside it
I did not see any relationship between the Dictionary and Listview.
at least you need to set the ListView elements again after you delete item from Dictionary, otherwise the ListView will not refresh by itself.
Fixed it, turns out I was repeating the process with the set listview block.
but now the problem is that I want the element to be shown in proper format. Now it looks like this
Whereas, I want the element to look like this
ABG
March 13, 2023, 4:00pm
16
Each of your dictionary values can be transformed into a YAML Element by replacing all its commas with \n.
To prepare your Elements list from your dictionary,
start with an empty Elements list
for each key and value in your dictionary
build a new Element from that key and value, applying your own artistry.
add the new Element to the Elements list
after the Elements list has been filled, set the ListView.Elements to your Elements list.
refresh the ListView