Question

I have a display form and a list web part just below that. When users click "add new item" on that list web part, I would like for the values to automatically be populated.

The url for the diplay form contains DispForm.aspx?ID=1, but when I open the NewForm.aspx, I would like to populate a field with that ID automatically. Can I pass that ID into the NewForm or at least into its url where I can retrieve it from there? All it seems to pass in is the list name that the display form is in.

Was it helpful?

Solution

Depending on your settings, the newform.aspx page will either open in a dialog (iframe) or open in a new page.

Here is how I address this issue in my SPELL library: I don't pass the ID in the URL, but instead I run a script on newform.aspx that follows these steps:

  1. When the new form opens, check the parent window
  2. if the parent exist (dialog), then the ID is included in window.parent.location.href
  3. If the parent does not exist (new page), then check the window.referrer

Note: in practice the newform.aspx page might be opened from more than one display forms. So you might need something more sophisticated than just splitting on ID=.

OTHER TIPS

You can parse the ID parameter from query string in Dispform.aspx, once you have the ID value you can update "Add new Item" link and pass ID from DispForm.aspx.

Please refer to Parse Query String from Javascript to parse URL and get value from Query String.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top