I have two lists:

  • List A: Products
  • List B: Requirements

I'd like to have a nice Create Requirement page launched from the Product Listing page.

I have a DVWP/Multi-Item View displaying all Products. Next to each product, there is a Create Requirement link. The hyperlink generates the Query String URL /Pages/Create-Requirement.aspx?Product=Product

On the Create-Requirement.aspx page, I have a DVWP/New Item Form. The form includes a lookup field back to the Products list. I would like the Query String parameter to populate that lookup field and for the field to be hidden.

I've seen different methods of using Javascript or jQuery to pass to a field on a Custom New Item Form - but not necessarily a DVWP/New Item Form. And it's easy to pass to a text field but not a lookup field. I even tried passing to a text field that would then populate the lookup by workflow on item creation but SPD won't do that (unless someone can think of workaround logic).

Hiding the field should be easy enough - I just can't make the lookup happy. (Lookups are never happy.)

  • Is your question different from this one here? @PirateEric's answer is basically the same (and mine as well) so perhaps we can merge these questions.
    – Kit Menke
    Feb 17 '12 at 20:27

This blog post from Microsoft is highly linked to and describes what you want to do. I've used it before, these days I typically use jQuery and SPServices. Setting lookups typically requires you to pass in the Lookup ID value or the ID;Descriptor.

Here's an actual example from a site of mine, it's setting a person/group field, not a lookup though. You can experiment with looking at the source of the rendered page to see what markup the lookup field generates, then try passing in either the ID or the description in the query string and setting the field to that. If it saves properly, then set the visibility to hidden.

var queryStringVals = $().SPServices.SPGetQueryString();
var insEmail = queryStringVals["InstructorEmail"];

Another example from some of my code, this is setting a >20 choice lookup field. It is using a hard coded value but so long as your query string variable passes over the proper vaule, it would work.

$("select[Title$='Department']").val('*Not Applicable - Student');

Or to abstract it to account more closely to your situation:

var queryStringVals = $().SPServices.SPGetQueryString();
var prod = queryStringVals["Product"];
  • Is there a similarly good write-up on the jQuery/SPServices model? I prefer that over Javascript.
    – Cory M
    Feb 17 '12 at 16:19
  • I'm not sure if there is. I think I have an example, if so I'll edit the post with it. Since you have control over the DVWP input form, it makes it fairly easy. you gove the fields you want to modify IDs or Classes you can easily target with jQuery. Then using SPSservices, you parse the query string and set the field value. Feb 17 '12 at 16:21
  • edited with an example, it isn't a lookup field, but shows how I parse the QS and update a field. Feb 17 '12 at 16:29
  • 2
    Keep in mind that jQuery/SPServices is JavaScript! Feb 18 '12 at 15:51
  • I could not figure out how to tweek the SPServices or the SPUtility code to get it just right - but the MS article PirateEric linked to worked out pretty easily - I was just initially daunted by the giant code block. I updated the field display name, the query string name, I tweeked "opts[i].value" to "opts[i].innerText" - and it works on a vanilla Web Part page with a number of different Web parts.
    – Cory M
    Feb 29 '12 at 20:54

Using Jquery and normal OOB Javascript functions we can easily implement this as below

<script type="text/javascript">
var url = new URL(window.location.href.toLowerCase());
var product = url.searchParams.get("Product"); //Product is the Name of Query Parameter passed through the URL
$( document ).ready(function() {
    $("select[Title='Requirements']")[0].value = product; // Title is the Display Name of the Lookup Field

Your Answer

