Search the Blog Minimize
spacer
DNNDev Blogs: Most recent blog entries Minimize

How To Build Relational Parent-Child Solutions In Xmod

Sep 8

Written by:
9/8/2009 10:47 PM  RssIcon

A parent / child solution is when you have a one-to-many relationship. Say you want to have an event management solution that includes registrations for those events. Each event could have many registrations. Or maybe clients and invoices – each client could have many invoices. This tutorial will explain how to answer this issue in Xmod.

 

 

 

 

 

A parent / child solution is when you have a one-to-many relationship. Say you want to have an event management solution that includes registrations for those events. Each event could have many registrations. Or maybe clients and invoices – each client could have many invoices.


The answer in Xmod is to have one form for events and one form for registrations and then relate the two. The example on the right shows the detail view of an electrical component in a online maintenance management system. It first shows the details of the electrical item. Below that are three Xmod modules inside a Tabs module. Each showing a different child form (IR Scans, Work History, and PM History) filtered to show only the records that relate to that electrical item.

This tutorial will explain, in a step by step process how to build a relational events management solution in Xmod.

1. Build two DNN pages - one for the parent grid/list view and one for the details view.

2. Go to the Projects section on Xmod’s website (under the “Other” menu tab) and download the project called Xmod Detail View for Xmod 5.0 – PA. Install this module as you would any other DNN module.

3. Add the Detail View Module to the DNN page you built for your detail view. While you are on this page write down the URL of the page. Then click the standard DNN settings option from that module’s action menu. After the settings come up take a look at the URL it will look like this at the end:


/tabid/56/ctl/Module/ModuleId/368/Default.aspx


Write down the ModuleID – in the above url the moduleid is 368

4. Build your parent (events) form, grid/list view, and details view.

4a. In your form you are going to add a field called EventID. This will be the field we use to link all child (registration) records to.

Hint

We custom build our own record ID instead of using Xmod’s built in record ID because it is easier to filter on a form field. Plus it gives us extra flexibility should we need it down the road. ID fields need to have values that are unique so no two records are the same. You can get Xmod to automatically add a unique value in your EventID field by combining the {XMOD_UserId} constant with the {XMOD_Now:format} constant with no formatters in the XMOD:Now constant. This will produce one long number that will be unique. If you want to hide this field from your users do NOT use an Xmod hidden field. Just add a style of display;none to a regular Xmod input field. In your form it would look like this:


<input ref=”EventID” width=”100” maxlength=”25” style=”display:none;”>
<default>{XMOD_UserId}{XMOD_Now:MMDDyyyyhhmmss}</default> </input>

4b. In your parent grid/list view we are going to build a “View Details” link (or button if you like) that passes two items to the details view page. The first is the record id that Xmod automatically assigns to each record. The second will be the value of the eventid field for that individual record. Passing two id’s solves some potential problems but you can do it with just the record id if you want. To build your View Details link we will make the target of the link the URL of the DNN details page that you wrote down. Your View Details link should look something like this:


<column header=”View Details”><a href=”http://www.yourwebsite.com/tabid/76/xmmid/368/
xmid/<xmod:recordid />/xmview/2/EventID/<xmod:field name=”EventID” />/
Default.aspx”>View Details</a></column>


xmmid = Xmod Module ID
xmid = Xmod Record ID


You pass variables in name/value/ pairs. So take the URL of the view details DNN page that you wrote down and add the xmmid, xmid, and EventID name/value/ pairs in between the tabid value and the /Default.aspx”  In the above code the xmid/<xmod:recordid /> is used to tell the Xmod Detail View Module which record to display and the EventID is used to filter the child records.

5. Now we need to configure the Detail View module on your view details DNN page. Just click the Configure menu item on that module’s action menu. Select the Xmod form and detail templates you want to use. You can leave the default values in the other fields.

5a. You can now test your detail view and ensure that it works. Click a View Details link in the parent grid/list view and you should be taken to the view details DNN page with the details of the item you selected shown in the Detail View module.

6. Next we need to build the form, grid/list view, and details view of the child (registrations) form. You will need to add the EventID field to this form as well.

7. Now we are going to add an Xmod module to the view details DNN page. In most cases you will want this module to be below the Detail View module showing the details of the parent (event).

7a. Next select the Configure Xmod Module under the module’s action menu. Configure this module to use the child (registration) form, grid/list view, and detail view. Then select the Data Settings Tab in the Configure Xmod Module screen.In the Data Settings tab you are going to check the Filter Using URL Parameter checkbox. Then you are going to find the Event ID field and type in the Parameter Name next to it the same thing - EventID (or whatever you named the parameter you sent from the parent grid/list view). Check both the Filter checkbox and the Exact Match checkboxes next to EventID.

Now you have filtered the child (registration) Xmod module based on the EventID sent in the URL when you click on a View Details link in your parent (event) DNN page.


And that’s it you’re done - with the exception of some of the hints I’ll give you below. You can add as many child records as you want. But if you get too crazy and have 15 to 20 Xmod modules on the same page your site performance might not be too great.

Hint #1

You can do all of this on a single page by adding the Detail View module right below your parent grid/list view module and configuring your target URL for the View Details link to be the same page that the grid/list view is on.

 

Hint#2

Adding child records. If a end user adds a child record and fails to input the eventid then the child record will be orphaned. To keep this from happening we usually include an Add New Record (Registration) button to our detail view page that automatically inserts the eventid of the shown parent (event) record into the Event ID field of the child (registration). Xmod 5.5 now has the ability to pass parameters via the Add button or edit button. You can read about this in the help file.

Once you have the eventid parameter being passed via the add button you will need to add the <parameter> tag to your child form to grab the parameter we are passing to it. Then you add the parameter as a default value to the Event ID field. Your form should look something like this:

<form format=”custom”>
<parameters>
<parameter name=”EventID” alias=”eid” default=”Enter Event ID”></parameter>
</parameters>
<controls>
<input ref=”EventID” width=”150” maxlength=”35”>
<default>{eid}</default></input>
!--- The rest of your form --!
</controls>
</form>


Now when you click the add new child (registration) button you will be taken to the registration form and the EventID will automatically be filled in.

 

Hint #3

Buy Fatgeorge’s Housekeeper add-on. What this add-on does is keep track of all your relationships and when a parent (event) record gets deleted it will automatically delete all of the associated child (registration) records at the same time. Housekeeper can also keep track of all file and picture uploads for a record and ensure they get deleted when the record they were attached to is deleted. Pretty cool.

 

Hint #4

If you have several child grid/list views you would like to associate with a parent you can buy the Tab Aggregator module from www.dnnstuff.com and place your Xmod modules in tabs below the parent detail view module. This is what was done on the screen shot on the first page.

 

Hint #5

To make all the modules on the detail page look as if it is just one form / template just turn off the containers on the modules and place them next to each other.

 

I hope you found this tutorial helpful and if you have any questions just ask in the forums!

Tags:
Categories:
Location: Blogs Parent Separator Greg Brown
spacer
dummy