I just got finished with this same issue. Look at this thread: Variables empty in online script (looping over dictionaries)
Some functions don’t translate from Python to JS, so you have to do some manual JS code. In that thread, they have pretty helpful explanations, a link to a very helpful Google doc, and a link to a code that works. I highly recommend downloading the PsychoPy version of that persons’ code and opening it in Builder to see exactly what they did.