This project has moved and is read-only. For the latest updates, please go here.

SPRedirectWithID and Multiple Parameters

Aug 29, 2010 at 2:36 AM

I am trying to use the SPRedirectWithID function to accomplish a "chaining" of forms, however the scenario is a bit different than the example included in the documentation and I'm having trouble getting it t work.  I have a list which include 12 content types, and I would like to find a way to walk the user through creating an item based on each content type without taking them to any other pages in between entries.  So, the user will begin at NewForm.aspx and there will be two parameters already included in the URL: ContentTypeId (required by SharePoint for the default list form to work properly), and a second parameter (we'll call it Param2) I am using to populate a field in the form via Javascript.  When the user clicks OK they should be taken right back to the same NewForm.aspx page with the same value for Param2, but with a different value for ContentTypeId.  I am providing the next ContentTypeId via a hidden dataview.  (I really don't need the ID of the item to be passed, but if I have to do that to get things to work that's OK with me.)

I believe I have the code set up as it should be, but I think I'm running into a problem with the additional parameters.  I have tried a ton of different ways of creating the newAction value and can't figure out how to get it to work.  I have tried variations of the following with no luck, maybe I just don't understand how the form action attribute works...when I set the action to point back to the same page on the first load, do I have to include the additional parameters?  (Note that I have changed "ID" to "NewID" for this scenario since the NewForm can't handle the ID parameter)

newAction = thisUrl + "?Source=" + thisUrl + "&NewID=" + lastID;

newAction = thisUrl + "?Source=" + thisUrl + "&ContentTypeId=" + ctype + "&Param2=" + value + "&NewID=" + lastID;

newAction = location.href + "&Source=" + thisUrl + "&ContentTypeId=" + ctype + "&Param2=" + value + "&NewID=" + lastID;

In each of the cases above the redirect back to the page never quite happens correctly because my ContentTypeId and Param2 values don't come through, although the NewID value does, so the page never recognizes it's loaded the 2nd time.  I've also tried this:

newAction = location.href + "&Source=" + thisUrl + "%26ContentTypeId=" + ctype + "%26Param2=" + value + "%26NewID=" + lastID;

In this case I get a 404 error as if the Url is invalid because the %26 values aren't handled correclty.  Is there something I'm missing or perhaps a better way to do this?


Aug 29, 2010 at 6:53 AM


If you're creating a single item, then you don't want to be going back to NewForm each time, right? If you do that, you'll end up with 12 different items.

For what you're describing, you want to create 12 different forms for creating a single item. Each form would display the subset of columns you want the user to work with on that form. You've use SPRedirectWithID on the initial NewForm, but then just pass the item's ID along to each of the other 11 forms, which would be variants on the EditForm.

Alternatively, you could consider using some sort of tabbed interface on a single form, but with 12 tabs, it may be much harder to go that route.


Aug 29, 2010 at 8:01 PM

Sorry, I guess I wasn't clear in my original post.  I have a list with 12 content types defined.  I want to walk the user through creating 12 items, one of each content type.  If it helps, I am working on an electronic benefit enrollment application.  I have a list (Enrollments) that has 12 content types defined - one for each type of benefit a user can enroll in (i.e. medical, dental, life insurance, 401(k), etc).  I would like to walk the user through creating their 12 entries in the Enrollments list, one for each content type (benefit type), one right after the other.  I want to display the newform for the first content type, have them complete the form and click OK, then display the same newform for the next content type.  So, the example would be display the newform for the medical benefit, allow the user to complete their selections and click OK, then display the newform for the dental benefit, etc.  The only thing that would change each time is the ContentTypeId parameter so that the default list form knows which content type to use and which fields to display to the user.

So, your first statement is correct: in effect I do want to go back to the newform each time and create 12 items, but by including the ContentTypeId parameter I should end up with one item for each content type.  I am just having trouble redirecting because of the additional parameters that I need to include, maybe I'm just not tacking them on to the URL correctly?  I think the problem is where I am trying to create the URL for the form's action attribute that will be set on the first page load, however the URL is not simply the address to the newform - it is the address to the newform plus 2 parameters.  So, in the action the URL and the Source will both include 2 parameters which are the same.  I tried tacking on the 2 parameters in the Source string with %26 instead of the ampersand but that isn't working.

Sorry for the confusion, hopefully I didn't just make it worse :)  Thanks for your help,


Aug 29, 2010 at 11:21 PM

Ok, I got it working.  Basically I can use a portion of the logic from the SPRedirectWithID function to redirect back to the same newform.aspx page but with a different ContentTypeId parameter each time.  I ran into problems when trying to create the newAction value because the original action was the entire URL (newform.aspx?ContentTypeID=x), which includes a parameter.  When I tried to add the Source string to the newAction value either the page would not redirect after submit or I would get a page not found error (because the Source string was the page address plus parameter also).  My problem ended up being the need to encode both the '?' and '&' in the Source string to "%3F" and "%26", respectively, so that they are considered a part of the Source string and not the original URL.  I had been using %26 already, just finally realized that the ? in the Source string had to be encoded also.

Thanks for your help!