This command will get the PID of the xterm process launched:
xterm & export APP_PID=$!
How can I get the window ID associated to that process (the xterm window ID)? I mean, the ID that xdotool selectwindow would return after clicking on the xterm window.