You might also consider some of these solutions mentioned in these threads if you were not already aware of them.
https://intfiction.org/t/passing-variables-from-parchment-i7-to-javascript-and-back/1326/1
https://intfiction.org/t/parchment-experimental-extensions/1425/1
Paul.