There are several ways to get an id from a requested form and set it as a request parameter on a subsequent web request. Remember that the querystring parameters are used on the form request before the form is retrieved and the extraction rules occur after the form has been received. This is all to ensure that the response to a formatted request was as expected.
Option 1: Add a class that inherits from ExtractionRule and override the Extract method. This method is often required for complex logic but it's more code to maintain. We can avoid this roll-our-own method in simple circumstances.
For a good reference, refer to Josh Christie's blog: http://blogs.msdn.com/joshch/archive/2005/11/17/494164.aspx.
Right-click the top node of the web test or its global "Context Parameters" context menu. Add a parameter name such as QueryStringPersonId and an initial value. If I expect to never have a value such as -2, then that is what I chose for my default in this example. This way if we ever see a -2 then the tests can report the error, create a TFS workitem or perform another task. It also makes it obvious when debugging the web test.
Now the variable can be set and retrieved throughout the test. The value should also be available for coded tests as described previously because it's in the test context. The value can be set from a specific form field extraction.
The context parameter can now be used in subsequent Query Strings.