This function allows you to redirect to a another page from a new item form with the new item's ID. This allows chaining of forms from item creation onward.
Important Notes: This function will not work in anonymous mode. See
this blog post for details on why. Also, there must be a redirect in place, as
rdoyle78 points out in the comments below.
Tip: If you are using this function in conjunction with others in the library, call SPRedirectWithID first, as it will speed up the redirection.
How Does It Work?
Assuming your NewForm is called NewFormCustom.aspx and the redirectUrl is set to
- On the initial load of NewFormCustom.aspx, the form action is changed to point back to the same page, with
?Source=NewFormCust.aspx?ID=[the last ID created by the current user]%26RealSource=[the actual Source for the page]. The
[the last ID created by the current user] is determined by calling the
- When the form reloads, because the ID is present on the Query String, the jQuery function then waits until
[the last ID created by the current user] is not equal to the value on the Query String. This ensures that the commit has completed. The
[the last ID created by the current user] is again determined by calling the
- The user should then be redirected to EditForm.aspx?ID=[the last ID created by the current user]
The page for the redirect. Upon save of the form, the page will refresh briefly and then be redirected to redirectUrl with the new item's ID on the Query String.
In some cases, you may want to pass the newly created item's ID with a different parameter name than ID. Specify that name here, if needed. The default is ID.
By placing the code below into any NewForm.aspx (or your customized version of it), the user will be redirected to EditForm.aspx with the ID for the newly created item as the value for OrderID. Thus, if the code is placed into the page:
the user will be redirected to
after creating the item.
The Source Query String parameter is preserved across the redirects, so:
will redirect to:
It is possible to override the redirectUrl specified in the options by calling the page with a Query String parameter called RedirectURL. This allows for occasional overrides, if needed.
will redirect to:
regardless of the value specified for redirectUrl in the options.