Hello, researching and trying and trying, I have realized something curious.
If I choose 1 or a few records in the grid, the value of the variable is copied to the clipboard, but if many records are chosen, even if the value of the variable is correct, it has the correct data, nothing is copied to the clipboard. That is calculated in the "for", I don't know if it is for speed reasons or something like that.
This is what ChatGPT tells me:
"The problem seems to be related to the time it takes for the for loop to execute when there are many items (i.e. getItemCount returns a large number). This can cause the browser to temporarily crash or a problem to occur in the code execution flow due to the accumulation of synchronous operations.
Also, if you try to copy to the clipboard after a long cycle, some browsers or API functions may fail due to runtime restrictions or memory limitations."
I could also skip copying the "id"s to the clipboard, for example, and just launch the search automatically, but I don't know how to force a search in the grid directly.