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

Originally posted on: http://geekswithblogs.net/SoYouKnow/archive/2009/05/15/passing-multiple-query-string-variables-using-spd-ndash-follow-up.aspx

How’s that for a long blog title?  Well, by far my most popular blog post has been about creating a Parent / Child relationship in SharePoint Designer and one question keeps getting asked over and over again: “How do I pass multiple values to the new item screen for the Child?”  So, I thought it was about time I actually told you how.  🙂  Are you ready?

As stated before, this blog is a direct continuation of a previous blog post Creating a SharePoint List Parent / Child Relationship – Out of the Box.  So, if you think you are lost, follow the steps on that blog post first, then come back.

First thing we need to do is break down what we are going to do into its parts and then tackle one at a time.  We are going to do the following:

  1. 1) Make the default Web Part invisible (in case you are modifying your DispForm.aspx file).
  2. 2) Drop new DataFormWebPart for parent on DispForm.aspx page
  3. 3) Set up a data connection to create a parameter on the Child Web Part that has the same value as the parameter on the Parent
  4. 4) Pass this parameter in the Query String to “NewForm.aspx” of the Child
  5. Maybe one of you geniuses out there know how to do this in fewer steps?

      Step 1: Make default Web Part Invisible on Parent DispForm.aspx

      If you are doing your work in the default DispForm.aspx of the parent (Issue from previous blog) then it is necessary to make the default web part on the page invisible.  DO NOT delete the default web part.  This will break your list views and you will not be able to get them back. 

      You actually should not be making the changes to the default DispForm.aspx page, you should create a new Display page and then associate this page as the Display Form for your list.  How do you do this?  Wow, you ask a lot of questions.  Okay.. Quickly:

    1. 1) Create new display page:  File->New->Page->List View Pages 
    2. 2) Right click on your List and select “Properties”
    3. image
    4. 3) Click on the “Supporting Files” tab
    5. image
    6. 4) Click on the “Browse” button next to the “Display item form” box and point it to your previously created form.

    *one caveat* I have had very limited success re-associating forms this way.  It is SUPPOSED to work fine.  Unfortunately, just because something in SharePoint is supposed to work, doesn’t mean it will.

    So, I’m going to assume that you are modifying the default DispForm.aspx and we need to make the default Web Part invisible.  We are doing this so we can add a DataFormWebPart for the Parent (Issue) on the page and set up a data connection between the child and parent. This data connection cannot be set up on the default DataFormWebPart. 

    In order to make the default Web Part Invisible follow these steps:

    1. 1) Search for the string “<IsVisible>true</IsVisible>” in DispForm.aspx of the Parent (Issue).
    2. 2) Replace “true” with “false”
    3. 3) Save the file

    How painless was that?  View the page now in SharePoint, you will see that there is no data displayed for the parent item.  On to our next step.

    Step 2. Drop new DataFormWebPart on page for Parent (Issue)

    We now need to drop a new DataFormWebPart on the page for the Parent (Issue) Web Part.  If you are asking yourself, WHY do I keep putting “(Issue)” after the word “parent”, then you obviously didn’t read my previous post.  The parent list in the previous blog was for storing Issues.  Got it?  Can I stop saying (Issue) now?  okay.. thank you.

    So, to drop the new DataFormWebPart follow these steps:

    1. 1) In the DispForm page of your Parent list, place your cursor after the “<asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>“ line in the aspx page (this is where we are going to put our new Web Part).
    2. 2) Click on “Insert->SharePoint Controls->Custom List Form”
    3. image
    4. 3) Make sure you have your parent list specified, click the “Display item form” radio button, then click “OK”
    5. image

    You will now see the display form for your parent on the page.  You will notice that this display form differs from the default web part.  You have a lot more control from here, you can even go in and modify the look and feel of the Display Form using standard html to make it look nicer.  Have fun with that, I’m not responsible for what you break.

    Step 3. Set up a data connection to create a parameters on the Child Web Part that have values from parent

    Okay, so now, let’s get the data from the parent into a parameter that the child can see.

    The following steps are necessary to create a parameter on the Child List for the “Status” field in the parent.

    1. 1) Go to the Common View Data Tasks for the Child List on the Parent DispForm.aspx page
    2. image
    3. 2) Click “Web Part Connections”
    4. image
    5. 3) Select “Get Parameters Form”
    6. image
    7. 4) Make sure “Connect to a Web Part on this page” is selected and click Nextimage
    8. 5) The Target Web Part should be your Parent List, action should be “Send Row of Data To”.  click Next
    9. image
    10. 6) Click on “<Create a new parameter>”
    11. image
    12. 7) Give the Parameter a name and then click OK (I used “ParentStatus”)
    13. image
    14. 8) Select the field in the Parent List to associate with the Parameter name you specified
    15. image 
    16. You can repeat steps 6 – 8 to create more parameters if you’d like.
    17. 9) Click Next
    18. 10) Just click Next on the next screen
    19. image
    20. 11) Click Finish!
    21. image

    *phew* If you think that too you a while to do, think who long it too ME to capture all the screens and type it in.  🙂  So, still with me?  Good!  We now have parameters created in our child list that we can pass as Query String variables.  On to the next step!!!

    Step 4. Pass this parameter in the Query String to “NewForm.aspx” of the Child

    We now need to modify the URL used to go to the “NewForm.aspx” page of the child so that it passes the parameter as a query string variable.  Just follow these easy steps:

    1. 1) Go to the link in your code.
    2. If you are going off the previous blog, find this line:
    3. <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>
    4. 2) Add the parameter as a Query String variable.
    5. Now add &amp;Status={$ParentStatus}” to the previous line as follows:
    6. <a href=”../Time/NewForm.aspx?IssueID={$IssueID}&amp;Status={$ParentStatus}” onclick=”javascript:this.href = unescapeProperly(escape(this.href)); GoToLink(this); return false;” target=”_self” class=”ms-alignleft”>Create a new Time Log Entry…</a>
    7. 3) Save your file.

    That’s it!  Now when you click on the link to create a new child entry it will pass both the ID of the parent and the status of the parent.  Just be sure to add JavaScript to the NewForm.aspx of the child to set the status field in much the same was as you did to set the ID field.

    So, there you have it.  Add as many query string variables as you like.  Hope this answers all the previous questions, if not.  What did I forget?  Again, thanks for reading my blog.  Hope you learned something useful.

    Families in Germany who are facing divers heartiness problem, such persons can buy drugs from the Web without prescription. With the market flooded with divers web-sites selling sundry medicaments, purchasing medicines from th WEB is no longer a trouble for common man. Certain medications are used to treat infections caused by dental abscesses. Of course it isn’t all. If you’re concerned about erectile health problem, you probably know about Xenical and Hoodia. Probably every adult knows about Garcinia. (Read more PhentermineXenical). The symptoms of sexual soundness problems in men turn on incredibility to have an erection sufficient for sexual functioning. Certain medications may add to sex drive difficulties, so its substantial to cooperate with your soundness care professional so that the prescription can be tailored to your needs. Preparatory to taking Levitra or other medicament, speak to your pharmacist if you have any allergies. Talk to your health care provider for more details. Preparatory to ordering this remedy, tell your physician if you are allergic to anything.