I am showing a picture via this command:
$gameScreen.showPicture(1,"test2",1,$gameVariables.value(0001),$gameVariables.value(0002),100,100,255,0)
but instead of the picture resource file name (test2), I want to put the picture resource's ID or index there. How do we get that?
you can't.
From the look of it this is the script equivalent of the event command "show picture". One of the main functions of that command is to assign the picture ID to the picture selected there, overwriting the ID assignment if the same Picture ID is set again in another show picture command.
The other picture commands can reference that ID after the show picture command has set it, but show picture itself needs the image name itself.
I don't know if I got you correctly, but you can assemble the pictures name if necessary by concatenating multiple parts with + :
"test" + $gameVariables.value(1)
could result in "test999" for example, depending on the value held by variable 1.
You should avoid leading zeroes when writing numbers in javascript. Otherwise they will be interpreted as octal numbers, 0215 would be equal to the decimal number 141 for example.