Solved

Pass Parent ID to Related List NewForm

Posted on 2012-04-09
1
1,781 Views
Last Modified: 2012-04-12
I have a "parent" list and a "child" list.  The child list has a lookup to a column in the parent list. I've placed a Related Item View on the parent list DispForm.

When a user is viewing the DispForm, they can click Add New in the Related Item view, to add a new child item.  But the value of the parent item is not passed to the child NewForm.

Any suggestions on how to achieve this (I do have SPD).

Many thanks.
0
Comment
Question by:TEEDA
1 Comment
 
LVL 15

Accepted Solution

by:
dp_expert earned 500 total points
ID: 37827400
Use javascript to get the ID from the URL and add to the URL of the "Add new item" link "?parentID=<id from url>".

Next use SPD to modify the newform.aspx. Use javascript  to read the parentID from url and then set the field to this value. Depending on the field you are using there will be different methods to achieve this - if you are using a single choice lookup field, then use this script (remember to input the ID of your field):

<script language="javascript" type="text/javascript">
parentID=window.location.href.split("parentID=")[1].split("&")[0];

_spBodyOnLoadFunctionNames.push("fillDefaultValues");

function fillDefaultValues(){
  var clInputId = "<ID of the INPUT FIELD>";//here input ID of the field
  value = parentID;

  var clInput = document.getElementById(clInputId);
  clInput.value = value;

  ShowDropdown(clInputId);

  var select=document.getElementById(clInput.opt);
  if (select != null){
   var opts = select.options;
   var l = opts.length;	
   for (var i=0; i < l; i++) {
      if (opts[i].text == value) {
        select.selectedIndex = i;
        break;
      }
   }
   OptLoseFocus(select);
  }
}</script>

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question