The way to do this is actually to pass the variable directly into the function
To do this the definition of the function needs to be changed to
function fillList (aips)
and when calling the variable needs to be surrounded by single quote marks (when just adding to the text of the form on ${aipids} is needed and this was where the problem arose)
fillList('$')