Creating a SharePoint List Parent / Child Relationship - Out of the Box

<update>

Be sure to check out the new video blog post based on this entry. It may be easier to follow and has a couple of upgrades from this post:  Creating a SharePoint List Parent/Child Relationship – VIDEO REMIX

</update>

 

First Things First

Okay, first off, my development blogs will fall into one of two categories “Out of the Box” or “Custom”.  My definition for “Out of the Box” is anything that can be done in SharePoint, SharePoint Designer, or InfoPath.  Another way to look at it is if you can do it “Out of the Box” you can do it remotely without having to use a VM or any sort of Remote Desktop Connection.  Of course, this may be everyone’s definition of “Out of the Box”, but I just want to make sure we are all on the same page when reading my Blogs. 

The Impetus

When we first started our SharePoint development efforts we had a requirement to write an application to track issues and projects as well as log time against them.  All of our development had to be Out of the Box because of the development constraints with Custom development and well, because at the time we didn’t really know what we were doing.  However, a couple of things came out of this development effort which I think will actually come in handy.  One of these was creating a Parent / Child relationship between lists so that we could track hours for a project or issue.   Unless there is some functionality in SharePoint that I’m not aware of (and there is a TON) you cannot create a list and have it automatically have any parent identifying field automatically set?  If I’m wrong, I’d love to know it.

Is There A Better Way?

One of the joys of SharePoint is that there are a lot of different ways to accomplish the same thing.  Is this the BEST method?  I doubt it.  This is what I was able to figure out and is pretty straightforward.  In fact, I just looked looked at some existing SharePoint templates to see how they did it.  This isn’t even my idea!  But I figure one of the benefits of a Blog is that it is a good place to document some of the things I’ve done and can easily go back later and find it.  So, this is more about me helping me than me helping you.  Yes, it’s out there.  I’m as selfish as my wife says I am. 

Blah… Blah… Blah… Just Show Me How You Did It

Okay! Keep your pants on.   First lets think of a real world scenario.  How about a time tracking application to track time against issues?  What a great idea!  Here are the steps we’ll take.

    1. Create Issue List
    2. Create Time Log Entry List
    3. Show time log entries for an Issue on an Issue View
    4. Create link on Issue View that passes Issue List ID to a page that creates a new Time Log Entry
    5. Create a page for creating a new Time Log Entry and store parent’s ID

Pretty easy eh?  Let’s get started. I’ll show you step-by-step in case you are as dense I am.

CREATE ISSUE LIST

Follow these steps from your SharePoint site (or watch the quick video, it always helps me to actually see it done)

  1. Click “Site Actions”
  2. Click “Site Settings”
  3. Click “Site Libraries and Lists”
  4. Click “Create new Content”
  5. Click “Custom List”
  6. Enter the name of the List (“Issue” in this example)
  7. Click “Create”

 

You now have a custom list created called “Issue”.  This list only has a couple of columns (Title, Created By, Modified By, and other auto-generated columns).  If you want to add more columns click on “Settings” then “Create Column” to add whatever columns you need.

image

CREATE TIME LOG ENTRY LIST

Follow the same steps above and create another list called “Time”. 

After the “Time” list is created, create a column for this list called “IssueID”.  Use the settings in the screen shot to the right. 

In addition to make this application more realistic add a couple of more fields.  Create a number field called “Hours” and a Date field called “Entry Date”.

So when we are done we will have these fields:
image
image

SHOW TIME LOG ENTRIES FOR AN ISSUE ON AN ISSUE VIEW

Okay, now this is where the fun starts.  Start up SharePoint Designer and open your site.  I suppose the same results could be achieved by editing the aspx pages directly, but again, I’m not that ambitious.  Open up the Issue Display form (DispForm.aspx).  I’ve heard some people say that you should not modify the default aspx files generated by SharePoint and that’s probably sound advice.  For the purposes of this tutorial I am going to use these files.  If you need help creating a new file shoot me an email.

image

Drag and drop the “Time” List to the bottom of the Issue DispForm.aspx file.

Let’s filter the Time list WebPart so that it will only show Time entries that belong to the Issue. This is done with the following Steps (or again, watch the video):

1. Open up the “Common Data View Tasks” for Time List.
2. Click “Filter”.
3. Click “Click here to add new clause…”.
4. Select “IssueID” for Field Name.
5. Select “Create a new parameter…” for Value.
6. Give the parameter a Name of “IssueID”
7. Select “Query String” as the Parameter Source
8. Enter “ID” for Query String Variable

CREATE LINK ON ISSUE VIEW THAT PASSES ISSUE LIST ID TO A PAGE THAT CREATES A NEW TIME LOG ENTRY

We now need to pass the ID of the current Issue as a query string variable to the aspx page responsible for creating a new Time entry.  Edit the Display page for Issue, and insert the following “<xsl:otherwise></xsl:otherwise>” code block within the <xsl:template> tag at the end of the Time list. :

<xsl:template name="dvt_1.rowinsert">
        <xsl:param name="IsInsertMode" />
        <xsl:variable name="Pos">_new</xsl:variable>
        <tr>
            <xsl:choose>
                <xsl:when test="$IsInsertMode = '1'">

                     .

                     .

                     .
                </xsl:when>
                <xsl:otherwise>
                    <td class="ms-vb" colspan="99">
                         <a href="../Time/NewForm.aspx?IssueID={$IssueID}" onclick="javascript:this.href = unescapeProperly(escape(this.href)); GoToLink(this); return false;" target="_self">Create a new Time Log Entry...</a>
                   </td>
              </xsl:otherwise>

The “{$IssueID}" is the parameter that we created above and will contain the ID of the current Issue.  The above code will create a link that looks like the following:

image

When a user clicks on the “Create a new Time Log Entry…” link they will be taken to the page to create a new Time list entry.  Save your changes and let’s make changes to the “NewForm.aspx” file for the Time list so that it stores the IssueID.

*UPDATE 3/4/09 ISSUES WITH MISSING XSL:TEMPLATE CODE*

**************************************************************************************

It appears as though I may have missed a step, or in some instances an additional step is needed in order to get the XSL code mentioned above.  If you are missing the aforementioned “xsl:template” code, follow these steps:

  1. Open up the “Common Data View Tasks” for Time List.
  2. Click “Date View Properties…”.
  3. Click on the “Editing” tab.
  4. Check the “Show inset item link” checkbox
  5. Press the “OK” button

     

At this point you should be able to find the “<xsl:otherwise>” code block described above and make the necessary modifications.  I hope this helps clear up any confusion.  Now… back to our regularly scheduled blog…

**************************************************************************************

CREATE A PAGE FOR CREATING A NEW TIME LOG ENTRY AND STORE PARENT’S ID

Probably the least intuitive part of this whole process is writing the code in the “NewForm.aspx” page so that it stores the ID of the parent Issue into the IssueID field of the “Time” list.  We have the parent ID of the Issue passed to the page in the “IssueID” query string.  To do this, simply add the following JavaScript to your “NewForm.aspx” page for a new Time list entry:

<script type="text/javascript">
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();

for (var i=0; i < args.length; i++) {
    var nameVal = args[i].split("=");
    var temp = unescape(nameVal[1]).split('+');
    nameVal[1] = temp.join(' ');
    vals[nameVal[0]] = nameVal[1];

setValueForFieldName("IssueID", vals["IssueID"]);
function setValueForFieldName(fieldName, value) {
  if (value == undefined) return;
    var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
    theInput.value = value;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
    }
  }
  return null;
}
</script>

I have found that the location of the script does matter.  I generally place it within the “PlaceHolderBodyAreaClass” ContentPlaceHolderId content tags. 

Conclusions?

There you have it, when you use the link on the Issue DispForm.aspx to create a new Time log entry it will create a Time entry with the IssueID set to the ID of its corresponding Issue.  When you view an Issue you will see a list of all Time entries corresponding to that Issue.  This also comes in handy for reporting on the data.  In our production environment I disabled allowing users to go directly to the NewForm.aspx page for a Time log entry so that there were no orphan Time entries out there.  Nothing spectacular, but it gets the job done.  If you’ve seen a better way of doing this, please post a comment with a link, I’m sure others would benefit as well. 

image

There’s quite a bit you can do from here.  To make this work more real world you would need to modify the “NewForm.aspx” page to hide the IssueID field and you could add some quick and dirty Workflows from SharePoint Designer to do things like sum up hours worked and store it in the Issue.

I’m more than happy to keep this application moving forward in future blogs if there is any interest, adding the above features and any others you might want to see?  Just let me know.

Also, if you found this blog completely worthless I’d like to know that as well.  I don’t want to make your trips here a total waste of your time, but I do offer a money back guarantee. 

<UPDATE>

There seems to be lots of interest out there in sending more than one value from the parent list to the NewForm.aspx page of the child list.  I finally got around to writing a blog explaining how to do this as a follow up to this blog.  You can find it here:

Passing Multiple Query String Variables Using SPD – Follow Up on Creating Parent / Child List Relationships

Enjoy!

</UPDATE>

<ANOTHER UPDATE>

Are you finding the JavaScript confusing?  I wrote a quick blog post where I break the JavaScript down into more detail.  Hopefully it will make a little more sense after you read it.  The blog is located here:

Setting SharePoint Form Fields Using JavaScript

</ANOTHER UPDATE>

posted @ Wednesday, December 24, 2008 12:34 AM

Print

Comments on this entry:

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Ben at 1/8/2009 2:35 PM
Gravatar
Question concerning the xsl:otherwise code - when I utilized this in the test environment we have, this produces an error saying this is not a recognized call in IE 6 - which our company utilizes.

Is their another alternative for this?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 1/8/2009 4:38 PM
Gravatar
Ben, you should be able to use IE 6. I modified the blog post to hopefully help you understand where the code block goes. If you are still having problems please let me know.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Adrian M Harris at 1/9/2009 7:08 PM
Gravatar
What I am really after is a way to do parent/child relationships using datasheet view (at least for the children).
That way data can be entered quickly like using a spreadsheet - without having to click a link, navigate to a new input page, click Save, and be taken back to the Parent list item.
Know how to do that?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 1/9/2009 8:35 PM
Gravatar
Adrian, The most simple thing to do would be to add a lookup field to your child table that is a lookup on the parent table. Then in the datasheet view people would use the lookup field to set the relationship. This wouldn't necessarily have to be the ID field, you could use the Title field or some other field. There are other options as well, but this would be the most simple and straightforward. If this won't work for you, let me know and I'll see what else I can come up with.

A possible scenario would be:

1) Create the relationships as listed in my blog
2) Add a look-up field to the child table using the title field of the parent.
3) Create a SharePoint Designer workflow for when a child entry is created that sets the IssueID field by matching the Title of the Parent.
4) Create your entries in the datasheet view using the lookup to set the relationship.

If the child entries already exist, make the SharePoint designer workflow fire on the modify of the child list

Make sense? Too simple? Hope it helps.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Adrian M Harris at 1/12/2009 9:42 AM
Gravatar
Thanks for the reply.
I am thinking this will be the only thing I can do, but I was REALLY not wanting to use a lookup field because it is going to get way too long to be useful.

I THOUGHT I had a simple solution using folders.
I created a simple workflow that add the URL to a custom field and then added a calculated field to the child Content Type that stripped off it's path from the URL, so then parent & child would have the same URL in a field that I could filter and group on.
HOWEVER...SharePoint did it to me again!
Whenver I tried to add new Items insed the folder in Datasheet view...it added the items to the top level instead of inside the folder!!!
Very Frustrating.

Thanks for the info though.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Adrian M Harris at 1/12/2009 6:19 PM
Gravatar
One last thing I have trying...
1. Created a new ASPX page using SharePoint designer.
2. Added Web Part and Parent List to the webpart.
3. Added another web part and the Child list to it.
4. Converted the Child list to an XSLT dataview.
5. Configured the Child list dataview to have the Save/Edit/Delete link/buttons.
6. Connected the 2 webparts so the Child list could be filtered by selecting a row in the Parent.

Now...I noticed that selecting a Parent item produced a URL with the "...SelectedID=1" of the item, and that URL did not change when I clicked "Insert" on the Child list dataview to create a new Child item.
Therefore, there should be some easy way to grab that ID from the URL and use it when entering new child items.
But I havent figured it out yet.....

Any idea how to grab and use that in a dataview on the same page?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 1/13/2009 11:38 AM
Gravatar
Adrian, Interesting... I'll play with it and see what I come up with.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Adrian M Harris at 1/13/2009 4:09 PM
Gravatar
Thanks!
Please let me know if you find anything. I'm still researching. (I'm not a programer/web developer).

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Alex Talarico at 1/15/2009 3:29 PM
Gravatar
just glancing over this - can you have multiple issues associated to the same time log entry? so for example a time log entry corresponds to both issue 1 and 3. Can you think of any ways to do this continuing from this approach or other approaches without custom code?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 1/16/2009 11:58 AM
Gravatar
Alex, I can think of a couple of ways to get the functionality you want, but what are you wanting the user experience to be like? Can you give me a couple of real world examples and I'll see what I can come up with?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by utam at 1/27/2009 2:17 PM
Gravatar
i am getting error: IE 6.0 (xsl:otherwise) is not permitted

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Jerry T at 1/29/2009 10:05 AM
Gravatar
Excellent post... extremely helpful!

I believe you missed one step before you update the link to create a new time log entry...

Go to the Editing tab of the Data View Properties and make sure to check off the "show insert item link" option

Note: this may be why some people were having issues with the xsl:otherwise -- checking off the "show insert item link" option will generate both the xsl:when and the default xsl:otherwise (which can then be replaced)

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 2/20/2009 8:51 AM
Gravatar
Thanks for the kind words and additional information Jerry.

If anyone is still having problems, please let me know.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by adeleh at 2/21/2009 6:10 AM
Gravatar
hi
this article was very good for me
very very thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Phase Dave at 2/22/2009 3:14 PM
Gravatar
I would like to be able to store an additional field other than ID in the child table. The value needs to come from the parent list item. How do I go about creating the parameter so that it is available in the newform.aspx file for the child list?

I have added a second call to setValueForFieldName() with the appropriate new field name specified. The problem is that the querystring does not contain a value for the second parameter I have set up.

My href tag looks like this in the dispform.aspx page for the parent (I am using contacts as the parent and computers for the child):

href="../Computer/NewForm.aspx?ContactID={$ContactID}&amp;ContactName={$ContactName}"

I have the created the parameter called ContactName and set its value the same was as ContactID but instead I used the field name "Full Name". The full name never appears in the link for adding a new child list item.

How do I create the parameter so that it gets its value from the parent list item and is passed as a query string parameter to the newform.aspx page for the child?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 2/22/2009 5:02 PM
Gravatar
Phase Dave,

The absolutely easiest way to set additional fields in your child item is to create a SharePoint designer workflow for when the Child List Entry is created. Then, using the ParentID on your child list just do the "set field in current item" action in the Workflow to set any additional fields in your child list with data from your parent list.

If it MUST be done in the query string let me know, but the SharePoint designer workflow literally takes 1 minute.

Hope this helps,
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Phase Dave at 2/22/2009 5:17 PM
Gravatar
I can use the workflow...I was going to use an update workflow anyways in the event that relevant parent data fields changed, I would need to update the child list item fields.

Why is the parent list item ID so easy to retrieve but not the rest of the fields in the parent list? If you have time, I would love to learn how to do this...

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Phase Dave at 2/22/2009 5:51 PM
Gravatar
OK, I am a bit confused on how to create the workflow. Using Sharepoint Designer, I created a new workflow attached to the child list and runs when the child list item is created. In step 1, I add a single action "Set field in current item". I set the update field to the appropriate child field to be updated.

When I try to set the "value to" field, I am confused. I change the source to the parent table and select the appropriate field. In the "Find the list item" section, I select the parent list ID field. When I attempt to set the "value" in the "Find the list item" section, I don't have the choice to select the child list item field. If I filter the value fields by "current item", the appropriate child list column is not available to select. If I select the child table instead of "current item", I am prompted to specify which specific child list item to get the value from. It is like I am in an endless loop of narrowing down my selection of matching the child to the parent.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 2/22/2009 7:21 PM
Gravatar
Hey Dave,

It appears that if you want to use the Parent ID in your child list to connect it to the parent list in the SharePoint Designer WorkFlow you will need to change the parent id in the child list from a "Number" to a "Lookup" where it is a look up on the Parent List ID field. This will also necessitate a change in the javascript to populate a list field instead of a text field. I'll give you the details tomorrow and update the blog. Sorry about the confusion.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Phase Dave at 2/22/2009 7:22 PM
Gravatar
I finally got the workflow working to update a child field with a parent field value when a new child item is created. The relationship of the ParentID stored in the child did not properly relate back to the parent ID in the workflow because the type of the ID field in the parent is "List Item ID" and the type of the ParentID stored in the child list is of type "Number".

I created a calculated field in the parent list called IDNum that is of type "Number" and is automatically assigned the value of the List ID. After doing this, I was able to relate the ParentID stored in the child list back to the IDNum field in the parent list. So for adding a new child list item, everything is working properly.

Now for updating the child list items when the parent list item changes, I am having problems. My idea for updating the child list items when the parent changes does not work because of the 1 to many relationship. It only updates one of the child list items. Any ideas for updating all of the child list items when the parent list item changes?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 2/22/2009 7:26 PM
Gravatar
Dave... if you really have to do something tonight, create a number field in your parent list that has the same value as its ID. You should be able to set this field on the creation of your Parent Item with a workflow. THEN connect to this new field in your workflow when the child list item is created. It's a hack, but it will work with the number field you have.

I hope I'm not getting too confusing now.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 2/22/2009 7:37 PM
Gravatar
As far as I know, one to many updates is NOT an option with SharePoint designer workflows. You will need to create a custom workflow to do this. It's on my list to blog about if I can ever find the time.

ACTUALLY, I have NOT tried this. But here is a horrendous idea for doing a one to many update:

1) create a field on your child list called "updated" that is of type YES/NO (default it to no)
2) Create a workflow that is fired when the parent list item is modified
3) Have your workflow find a child item based upon parent id in the child list and where "updated" is equal to "NO".
4) make the change to the child in your workflow and also set the "updated" field to "YES" in the child item
5) Create a workflow for your Child List that is fired whenever the child is modified
6) Cause THIS workflow to modify the parent list in some way so that it fires the parent's workflow again.

Conceptually this would keep firing the parent workflow until all the children have been updated? Does this make sense? I DON'T condone this because this is stuff SPD workflows are not really meant to do. A Custom Workflow is the correct answer. I can't even guarantee this will work.

good luck and thanks for the comments!

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Phase Dave at 2/23/2009 11:39 AM
Gravatar
Thanks for the suggestion. I think I am just going to try to create a custom workflow using visual studio...

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Tina at 3/3/2009 12:45 PM
Gravatar
Hi-
I am lost at the step where you are supposed to "Edit the Display page for Issue" - I do not have the code line "<xsl:template name="dvt_1.rowinsert"> " on that display page.

Also seems counter intuitive that there would be a rowinsert on the display page?

Can you possibly break this step down in a little more detail- i'm a total newbie at SP.

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Sunil at 3/4/2009 11:07 AM
Gravatar
For some reason, the NewForm.aspx gets the query string right, but the Javascript doesn't populate the IssueID field...any ideas?
Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 3/4/2009 11:13 AM
Gravatar
Tina,

Look at "Jerry T"'s comment. I'll try and update the blog today if I can find the time. Sorry for not getting to it sooner.

Sunil,

Is your IssueID field a lookup or number? If you followed the blog exactly then it is probably a JavaScript issue. Make sure it is correct and placed in the correct location. A quick and dirty way to check to see if your JavaScript is being executed is stick an "alert([message])" in the JS and see if you get the alert.

Thanks for the feedback!
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 3/4/2009 2:04 PM
Gravatar
For everyone that had issues with the "<xsl:otherwise>" code block I modified the blog to add an additional step if need.

Please let me know if you have any other problems.
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Sunil at 3/4/2009 3:24 PM
Gravatar
Mark,

This seemed to work after I added this line

_spBodyOnLoadFunctionNames.push("setValueForFieldName");

Is this required for the script to be executed.

Thanks for the great post. Really helpful.

Sunil

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Cherie at 3/12/2009 12:32 PM
Gravatar
This is great! Thanks!
I can't get the field to populate - I am still looking at it, but every other step works great and saved me a lot of time.
Thank you!

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 3/13/2009 1:34 PM
Gravatar
Cherie,

Make sure the JavaScript is in the correct location on your NewItem.aspx page. It MAY not be getting executed. A simple way to test is to stick an "alert('message');" in there and see if the alert is displayed.

Also, if your ID field is a lookup field you will need to use slightly different javascript:

function setLookupFromFieldName(fieldName, value) {
if (value == undefined) return;
var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
if (theSelect == null) {
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
// theInput.value = value;
ShowDropdown(theInput.id);
var opt=document.getElementById(theInput.opt);
setSelectedOption(opt, value);
OptLoseFocus(opt);
} else {
setSelectedOption(theSelect, value);
}
}
function setSelectedOption(select, value) {
var opts = select.options;
var l = opts.length;
if (select == null) return;
for (var i=0; i < l; i++) {
if (opts[i].value == value) {
select.selectedIndex = i;
return true;
}
}
return false;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}

That's some old code I had and might need to be cleaned up a little. Hope it helps.

Let me know if you are still having issues!
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Michael at 3/17/2009 8:14 PM
Gravatar
Mark,

Thanks for an excellent post.

I'm nearly positive I should be able to send multiple parameters on the query string when the DispForm.aspx page is displayed, but I've tried several things to no avail.

Using your example above, say I wanted to display the Issue DispForm.aspx page and send the ID field, and another field (any other field, pick one) on the query string, and I've added an appropriate, matching field to the Time List.

I want to filter the Time List using both the parameters passed on the query string to the DispForm.aspx page.

While I'm fairly new at this, seems like it ought to be pretty simple, but again, I've yet to be successful.

Thanks, in advance, for any help you can give.

Thanks, again, for an excellent article.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Vidette at 3/25/2009 2:26 PM
Gravatar
Great Article! This really helped me and I was able to follow it and get it working pretty easily.

One question however related to navigation.
Now that I have the "Create a New Time Entry" on the Parent List Page , I am able to sucessfully create the New Time Entry and after it is created it takes me to the All Items List View for the Time List. This is a sharepoint default wherein after you signup to a list it takes you back to all items in the list. IS there anyway I can go back to the specific item that I created the time log from?

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 3/25/2009 4:08 PM
Gravatar
Vidette,

I know what you are expressing is a common problem and I have yet to find a great solution (although I have not had time to investigate completely). Let me do some digging and I'll write a blog about what I come up with.

Thanks for the kind words,
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 3/25/2009 4:33 PM
Gravatar
Michael,

I believe you can achieve your desired functionality by playing with the "Web Part Connections". Open the “Common Data View Tasks” for your Time Log list (little arrow button on the top right of the web part in SP Designer). Then click on "Web Part Connections..."

This will open up a wizard that will allow you to get filter or parameter values from the Issue list. It should let you map fields to the child list to filter it.

Let me know how it goes and I can try to throw together a blog post to give more detail.

Good luck!
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Haley at 4/7/2009 4:24 PM
Gravatar
Wonderful post and worked like a charm!

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mathew at 4/8/2009 1:34 PM
Gravatar
Hi,
I have working at this for two days + and I can't get the <xsl:otherwise></xsl:otherwise> to accept my parameter as it keeps saying it can;t resolve the parameter/field. I have created the filter and parameter as listed and used the tweak of adding the edit option to bring up the <xsl:otherwise></xsl:otherwise> clause. Any help would be appreciated.

Mat

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mathew at 4/8/2009 3:32 PM
Gravatar
Hi,
I finally worked out what I was doing wrong. I wasn't using the DispForm.aspx as the page as I was trying to use a custom page which was showing a list and of course there was no context of the current selected parent which is why the parameter setup was failing.

I have it working which is huge :-) however I was wondering if there was a way of making use of the filter process which you can use to select an item in a list and pass a field value as a filter to another webpart. This way you would be able to have the add child in other locations.

Thanks again for your great post as it has been one of the best finds for a long time :-)

Mat

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 4/9/2009 11:12 AM
Gravatar
Thanks for the kind words Mat,

Have you tried using Data Connections to achieve the functionality you are wanting? Give me a scenario for how you'd like it to work and I'll investigate.

Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Maja at 5/7/2009 3:51 AM
Gravatar
I have problem with "<xsl:otherwise>" code block. I don't know where to put it. My Issue display page doesn't have "dvt_1.rowinsert".
This is what I have:
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="nowrap">Naslov</th>
<th class="ms-vh" nowrap="nowrap">IssueID</th>
<th class="ms-vh" nowrap="nowrap">Izmijenio</th>
<th class="ms-vh" nowrap="nowrap">Izmijenjeno</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<xsl:value-of select="@Title"/>
</td>
<td class="ms-vb">
<xsl:value-of select="format-number(@IssueID, '#,##0.00;-#,##0.00')"/>
</td>
<td class="ms-vb">
<xsl:value-of select="@Editor" disable-output-escaping="yes"/>
</td>
<td class="ms-vb">
<xsl:value-of select="ddwrt:FormatDate(string(@Modified), 1050, 5)"/>
</td>
</tr>
</xsl:template>

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Maja at 5/7/2009 6:26 PM
Gravatar
I read comments above and have everything working.

Now, I would like to have something like Dave - to be able to store an additional field other than ID in the child table. I have the Status field in parent list item that I would like to use as default value for Status field when creating new child item. Status field is choose field in both lists.

I think that I need to create the parameter so that it gets its value from the parent list item and pass it as a query string parameter to the newform.aspx page for the child.

What do I need to do to achieve this?

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by TaffyLewis at 6/5/2009 1:15 PM
Gravatar
I got everything working ok, but the child list will not allow me to edit from the parent list. What's that about?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Paul at 6/15/2009 11:17 AM
Gravatar
Mark
Did you ever come up with anything for Adrian (1/13/2009). I have the same issue in that I do not want to use a lookup since it will be too long a list to select from.
At the moment I have connected web parts (Customer and Payments) both as datasheet views. I would like to populate the new Payment record row with the related Customer ID. MSAccess does it automatically with a sub form and it would be nice to createsimilar functionality in WSS. Any other solution to passing a new ID would also be really helpful. Thanx.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Gilbert at 6/24/2009 10:14 AM
Gravatar
Great article, however I'm having the same concern as vidette concerning the navigation.

Now that I have the "Create a New Time Entry" on the Parent List Page , I am able to sucessfully create the New Time Entry and after it is created it takes me to the All Items List View for the Time List. This is a sharepoint default wherein after you signup to a list it takes you back to all items in the list. Is there anyway I can go back to the specific item that I created the time log from?
Did you find any solution for the navigation problem?

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 6/26/2009 11:34 AM
Gravatar
Gilbert and Vidette, take a look at the following link. This should help with your issue:

http://office.microsoft.com/en-us/sharepointdesigner/HA101191121033.aspx


Good luck!
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by AJ at 6/26/2009 2:16 PM
Gravatar
Excellent article... exactly what this SharePoint Designer newbie needed... thanks for taking the time to write such a detailed post.

Regards, AJ

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Rob Garrett at 7/21/2009 8:21 PM
Gravatar
Awesome, this is exactly what I was looking for.
Thanks for the post.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Paul at 8/25/2009 7:48 PM
Gravatar
Mark, I have two issues.
1. my DispForm page for Issues is missing the Hours and IssueID columns for Time, even thou they are in the Time list.
2. when I click Create a new Time Log Entry, my IssueID row contains {$IssueID} instead of the issue number.

Where did I go wrong?

Thanks.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mindaugas Bliudzius at 9/17/2009 5:32 AM
Gravatar
One more way to achieve this http://www.sharepointdrive.com/blog/Lists/Posts/Post.aspx?ID=6

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Ron at 9/30/2009 1:13 PM
Gravatar
HI,Thanks for sharing a knowledge.I am trying to implement same thing u did.now i want to hide insert link at bottom of web part based on field value how can i achive this ? any advise on this or any link which can guide me ....

Thanks

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by James at 10/2/2009 7:12 AM
Gravatar
Perfect, just what I wanted to do, but rather than adding Time Logs one by one through a form, can you think of a way to insert a Time Logs datasheet and populate the Issue ID with each new row added?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 10/2/2009 8:15 AM
Gravatar
Hey James, This can be done fairly easily. Follow these steps:

1) Make sure you have a unique field on the Issue log, I recommend some sort of issue # like you would find in Remedy (SR0003930290).. you could even use the Issue name, but it has to be unique!
2) Add this same field to your time list

3) Create a Workflow in SPD for when a Time entry is created and when a time entry is created set the IssueID of the Time entry based on the Issue with the same unique field identifier used in #1, and #2
4) When you insert values into your data sheet view for Time entries, make sure to enter the value for the unique field. When the workflow fires it will take care of the rest.

Of course, this is just a step above manually entering the IssueID itself, but if you are importing data from external systems (like Remedy) then you already know this "unique" field and it works nicely.

The bottom line is there HAS to be some unique field in Issues and a value for the unique field has to be stored in Time Logs so that some relationship can be made.

Actually.. now that I think about it, I wonder if it would be possible to have a Query String variable of the IssueID on the datasheet entry of the Time Logs and use that? Hmmm... might be something to investigate.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Mark at 10/2/2009 8:16 AM
Gravatar
Ron,

I'm thinking some JavaScript may be able to help you here, but I'd have to investigate further when I have time. If I run across anything I'll let you know.

Good luck!
Mark

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Melanie at 10/12/2009 3:20 PM
Gravatar
Awesome post, everything appears to be working great except one for this...

When 'Create new...' is clicked, it opens the child's NewForm with the correct querystringin the URL but it does not appear in the new record's 'VisitID' field (which is the only area I changed in the sript below). Any suggestions would be greatly appreciated.

<script type="text/javascript">
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();

for (var i=0; i < args.length; i++) {
var nameVal = args[i].split("=");
var temp = unescape(nameVal[1]).split('+');
nameVal[1] = temp.join(' ');
vals[nameVal[0]] = nameVal[1];
}
setValueForFieldName("VisitID", vals["VisitID"]);
function setValueForFieldName(fieldName, value) {
if (value == undefined) return;
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
theInput.value = value;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
alert(tags[i].title);
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
</script>

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Amjad Ali at 10/13/2009 4:41 AM
Gravatar
This is really excellent!

Just one question – is there a way that IssueID field can be automatically populated it’s value from the Issue ID?

Cheers

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by bespoke software at 10/26/2009 10:21 AM
Gravatar
Humm... interesting,

Its really easy to create a sharepoint list, these are great instructions,

Keep up the great work,

Anyway, thanks for the post

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Vijay at 11/2/2009 7:38 AM
Gravatar
Hi,
first of all thanks for a nice article.In master child forms,when we use a lookup for child data and update the master record ,how can we cascade these updates to the child reecords.Example we have meetings list and agenda list.we are using agenda items lookup in the meeting creation form.so when we assign agenda items to meeting item,in the agenda list the assigned agenda items should be linked to current meeting id .

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Ramon Torras at 11/12/2009 11:17 AM
Gravatar
Hi,
Fantastic post!! but I have a Image Library instead child list.

And It doesn't work, because first call upload.aspx...

Can you help, me?

Thanks
Ramon

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Jane Larsen at 12/2/2009 6:40 AM
Gravatar
Problem with folders: Anyone has a solution for using folders to organize "issues"? In my own solution I can't use the edit buttons for the "time log entries", because et states that the items does not exist...

Any ideas on how to handle the parent items in folders and still get to set the correct ID's etc.?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Doug Beebe at 12/2/2009 11:52 AM
Gravatar
Great article! How can I add a link to the child item from the parent display form? When I go to "Edit Columns," I don't have the typical choice for the built-in "Title (linked to item with Edit menu)."

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Leo Fernandes at 12/14/2009 12:32 PM
Gravatar
This article is super! Thanks so much. I do have one question though. Is it possible to get the new time log entry to be put in a folder within the Time list? rather than at the root level?
Any help would be much appreciated.

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Deb Klenke at 12/28/2009 9:50 PM
Gravatar
Hi Mark, I see it has been a while since you have responded. I hope you are still checking your blog. I have the same problem as Ramon Torras on 11/12/2009. I need to autopopulate a field in a pic library from a list. I've been able to pass the id through the upload form but can't seem to bring it into the edit form. Any ideas?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Parisa at 1/6/2010 3:41 AM
Gravatar
Thank you for your useful article, it works great. But i have a question! I need to create a list that It;s items will automatically added when i create details for the master list. I mean a list that have combination of items of parent and child, both..
Would anybody can help me in this case?

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by Kylie at 1/6/2010 8:34 PM
Gravatar
I love your post!!!!!!!!!!!!!!!!!!!!!!!!!!! You just saved me and successfully wasted 2 weeks of my headache!

Keep up the great tutorial site and I will definitely look into your blog first before asking my sharepoint team for help. (look how much I looked up to you!)

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box

Left by mike16os at 2/9/2010 6:46 AM
Gravatar
Thank for great tutorial.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«March»
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910