Geeks With Blogs

News





The SharePoint Hillbilly Fewer Big Words... More Pretty Pictures...

<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>

<update 12-16-2010>

I FINALLY got around to blogging how to do this in SP 2010, you can find that blog here:  Creating A SharePoint Parent/Child List Relationship– SharePoint 2010 Edition

</update 12-16-2010>

 

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 on Wednesday, December 24, 2008 12:34 AM | Back to top


Comments on this post: Creating a SharePoint List Parent / Child Relationship - Out of the Box

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Ben on Jan 08, 2009 2:35 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.

Left by Mark on Jan 08, 2009 4:38 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Adrian M Harris on Jan 09, 2009 7:08 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Mark on Jan 09, 2009 8:35 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Adrian M Harris on Jan 12, 2009 9:42 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Adrian M Harris on Jan 12, 2009 6:19 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Adrian, Interesting... I'll play with it and see what I come up with.
Left by Mark on Jan 13, 2009 11:38 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thanks!
Please let me know if you find anything. I'm still researching. (I'm not a programer/web developer).
Left by Adrian M Harris on Jan 13, 2009 4:09 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Alex Talarico on Jan 15, 2009 3:29 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Mark on Jan 16, 2009 11:58 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
i am getting error: IE 6.0 (xsl:otherwise) is not permitted
Left by utam on Jan 27, 2009 2:17 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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)
Left by Jerry T on Jan 29, 2009 10:05 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thanks for the kind words and additional information Jerry.

If anyone is still having problems, please let me know.
Left by Mark on Feb 20, 2009 8:51 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
hi
this article was very good for me
very very thanks
Left by adeleh on Feb 21, 2009 6:10 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Phase Dave on Feb 22, 2009 3:14 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Feb 22, 2009 5:02 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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...
Left by Phase Dave on Feb 22, 2009 5:17 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Phase Dave on Feb 22, 2009 5:51 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Mark on Feb 22, 2009 7:21 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Phase Dave on Feb 22, 2009 7:22 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Mark on Feb 22, 2009 7:26 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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!
Left by Mark on Feb 22, 2009 7:37 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thanks for the suggestion. I think I am just going to try to create a custom workflow using visual studio...
Left by Phase Dave on Feb 23, 2009 11:39 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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

Left by Tina on Mar 03, 2009 12:45 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
For some reason, the NewForm.aspx gets the query string right, but the Javascript doesn't populate the IssueID field...any ideas?
Thanks
Left by Sunil on Mar 04, 2009 11:07 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Mar 04, 2009 11:13 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Mar 04, 2009 2:04 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Sunil on Mar 04, 2009 3:24 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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!
Left by Cherie on Mar 12, 2009 12:32 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Mar 13, 2009 1:34 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Michael on Mar 17, 2009 8:14 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Vidette on Mar 25, 2009 2:26 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Mar 25, 2009 4:08 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Mar 25, 2009 4:33 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Wonderful post and worked like a charm!
Left by Haley on Apr 07, 2009 4:24 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mathew on Apr 08, 2009 1:34 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mathew on Apr 08, 2009 3:32 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Mark on Apr 09, 2009 11:12 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Maja on May 07, 2009 3:51 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Maja on May 07, 2009 6:26 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
I got everything working ok, but the child list will not allow me to edit from the parent list. What's that about?
Left by TaffyLewis on Jun 05, 2009 1:15 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Paul on Jun 15, 2009 11:17 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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

Left by Gilbert on Jun 24, 2009 10:14 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Excellent article... exactly what this SharePoint Designer newbie needed... thanks for taking the time to write such a detailed post.

Regards, AJ
Left by AJ on Jun 26, 2009 2:16 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Awesome, this is exactly what I was looking for.
Thanks for the post.
Left by Rob Garrett on Jul 21, 2009 8:21 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Paul on Aug 25, 2009 7:48 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
One more way to achieve this http://www.sharepointdrive.com/blog/Lists/Posts/Post.aspx?ID=6
Left by Mindaugas Bliudzius on Sep 17, 2009 5:32 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Ron on Sep 30, 2009 1:13 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by James on Oct 02, 2009 7:12 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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>
Left by Melanie on Oct 12, 2009 3:20 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by Amjad Ali on Oct 13, 2009 4:41 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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
Left by bespoke software on Oct 26, 2009 10:21 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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 .
Left by Vijay on Nov 02, 2009 7:38 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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

Left by Ramon Torras on Nov 12, 2009 11:17 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.?
Left by Jane Larsen on Dec 02, 2009 6:40 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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)."
Left by Doug Beebe on Dec 02, 2009 11:52 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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.
Left by Leo Fernandes on Dec 14, 2009 12:32 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Deb Klenke on Dec 28, 2009 9:50 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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?
Left by Parisa on Jan 06, 2010 3:41 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting 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!)
Left by Kylie on Jan 06, 2010 8:34 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thank for great tutorial.
Left by mike16os on Feb 09, 2010 6:46 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thanks I spent much time trying to find information on this. You did this extremely well! I am new to SharePoint and you explained things in great detail! THANKS
Left by Narasimharao on Apr 08, 2010 2:54 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Thanks for a great article and idea.

Has anybody figured out how to do this with a document library instead of a list? I have the same issue as Ramon and Deb: I can get the ID to the Upload file, but then I am stuck.
Left by Andreas on May 25, 2010 8:38 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Not only a great post but very nice presentation as well.

I've implemented this a couple of times and it works great. I'm looking for a way to automatically delete the child tasks if the parent task is deleted. Since SPD cannot initiate a workflow based off of an Item being deleted I'll have to associate a workflow with the child list.

Something along the lines of - "check to see if the a parent ID that matches the child's ID exists in the parent list. If not, delete the child record(s).

Any ideas?
Left by Dave on Aug 31, 2010 9:59 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
I have followed these steps, but it does not work for me. When I open the DispForm, the subform does not seem to be getting the value for the parameter that would filter the time entries for that issue.

The parameter is set to get its value from a Query String, using ID as the variable. However, it seems there is a step missing to have the parent form feed that variable.

Am I missing someting?
Left by LT on Sep 10, 2010 6:01 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
This is very close to what I want to do, but what I'm looking to do is to be able to add child items on the New form, without navigating away. Is that possible?
Left by Carlos on Sep 24, 2010 4:54 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Hello,
This is a great article. I had tried your solution and work great, the problem that I have is
that instead of filtering the list by the ID, I want it to filter by the Type of issue.

The goal is to display for each issue, the list of resolution related to that issue. The two lists are related by issue type.

This is the scenario, I had 2 list:
1. Issue list that contain a field: issueType that is a single line of text (then it will be a lookup, but for the first step I will keept it simple in order to work)
2. Issue Resolution list that the Title column will contain the type of issue. So this column will be used to join the two lists, and had some additional columns that do not matter.

So the filter reads: Title equals [IssueType] (“Query String”).

I had tried this and worked well with the ID as well by filtering the list having IssueType equal to a constant value.

It look like the join between the two list is not done right, but I do not understand why.

Any help, will be greatelly appreciated.

Thanks.
Left by Mari on Oct 07, 2010 9:15 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Finally got around to doing this in SP 2010:

http://sharepointhillbilly.com/archive/2010/12/16/creating-a-sharepoint-parentchild-list-relationshipndash-sharepoint-2010-edition.aspx
Left by Mark on Dec 16, 2010 6:24 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Hi,

I am trying to setup our team sharepoint site for internal project tracking.

We have number of projects listed on our site with Project Name, Type, Lead, Business Area, Impact, RAG Status.

Each project has multiple environment, i.e Prod, C&R, QA, UAT, Dev etc.

What we like to do is to link each environment deliverables with RAG status for one project. So that each project's environment clearly viewable. Currently all envionrment is bundled into one item. So can't really tell clearly what enviornment is complete and what is in progress etc.

Not sure anyone has similar relationship built for their site.

Please let me know.

Thanks
Left by Al on Dec 30, 2010 12:31 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
Hello Mark, thanks for this great "how to" create A Parent Child list relationship and i'm wondering if i might be able to access the videos with the "hot to" in another way as they don't seem to be to be accessable via my IE?
Thanks Mark!
Left by Bob Kennelly on Jul 03, 2011 8:32 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
As a "learn as you go" user, your blogs are extremely helpful (and funny...) thanks for all the hard work you do & keeping this site up!
Left by Jen on Aug 23, 2011 12:30 PM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
I am going nuts with this... Can I get a filtered web part to pass multiple values to a consumer web part and display corresponding records. For instance, I have employees working assigned to regions (many to one relationship...several employees assigned to EMEA but One employee can be assigned to one region only). This is in my Assigned list. Employees are billed at different rates for each month. This is in my billing list. Each region manager can view only employee records for his region. SO I filter the view of the Assigned List in the region page (Region column in Assigned = "EMEA"). To connect to the corresponding employees in Billing List, I am expecting to use "Provide Data To", but the !@#$## says the web parts are not compatible with this type - and cant get it to work in SPD (in the browser it s greyed out). I either get all of the billing data for ALL regions or I get only the first record with the Provide Row To connection type. What am I doing wrong???? How can I get this to work... please I am bald as it is!!!
Left by Anand on Sep 06, 2011 1:45 AM

# re: Creating a SharePoint List Parent / Child Relationship - Out of the Box
Requesting Gravatar...
You have just saved my day!! I was going mad with, which direction should I go. You have shown me the path. Now I can go on my own :)
Left by Abrar Fahad on Sep 20, 2011 3:29 AM

Your comment:
 (will show your gravatar)


Copyright © Mark Rackley | Powered by: GeeksWithBlogs.net