Solved

Pass Parent ID to Related List NewForm

Posted on 2012-04-09
1
1,713 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Last week I faced a strange issue recently, i have deployed SharePoint 2003 servers for one project and one of the requirements was to open SharePoint site from same server. when i was trying to open site from the same server i was getting authentic…
If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now