Thursday, August 12, 2010

Re-Direct With ID - REVAMP

Ended up re-working the process from my previous post!

RECAP: The goal is to allow users to enter a list item and associate a number of items in ANOTHER list with that original list item. In this case, we have a list of projects and we want to associate multiple notes with a single project.

My original approach was to use URL parameters wherever possible. That still works in a few cases, but I found that it works better to skip the URL hassle. Instead, I hid a data view web part on the child (the notes list) newform page.

The hidden data view web part is filtered to show only the ID of the project most recently modified by the current user. That ID is displayed in a cell with the ID "ProjectID".

On the same page, my add-a-new-note form has a hidden field that accepts that ID. That field is populated using the following Javascript:



NOTE: In this case, the ProjectID field in my child list is a lookup field. If you have a different type of field, you'll need to alter the javascript to some degree. The holy grail of info on setting values in SP forms with Javascript is here.

Once the data is ready, I wanted to send the user back to the display form for the project they were working on (I would have preferred to send them to the edit form, actually, but doing so can cause save conflict errors). To do that, I had to go back to the URL parameter, so I can specify what project I want to display.

It took a smidge of Javascript magic again to properly insert the project ID into the URL. Here's the code:



This is called in a custom submit button:



And there you have it!

No comments:

Post a Comment