Can I use SPRedirectWithID to redirect NewForm/EditForm to DispForm?

Oct 28, 2014 at 8:19 PM
I want to redirect NewForm/EditForm after OK or Cancel is clicked to the DispForm for the same item. Can I use SPRedirectWithID for that? Do I have to put it in each NewForm/EditForm page? Do I need any other code to make it work?
Coordinator
Oct 28, 2014 at 8:40 PM
You can use it in the NewForm, though I've had one report that it isn't working on 2013.

You don't need it on the EditForm because you already know the ID.

M.
Oct 28, 2014 at 9:15 PM
It works on the NewForm, but it shows EditForm briefly before showing the DispForm (my redirectuURL).

Also, it doesn't work when I press cancel. Should it? How can I do the same with Cancel?
Oct 28, 2014 at 9:18 PM
Also, for EditForm, just write the redirectURL and leave out the qsParamName? Would this redirect to DispForm after EditForm is submitted?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" language="javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.01/jquery.SPServices.min.js"></script>
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $().SPServices.SPRedirectWithID({   
            redirectUrl: "DispForm.aspx"
        });
    });
</script>
Coordinator
Oct 28, 2014 at 9:36 PM
SPRedirectWithID won't do anything on an EditForm. You already have the ID on the Query String, so just use that to build your URL.

When you use SPRedirectWithID on theNewForm, it's actually coming back to that form and waiting until the new item is actually in the list. The whole reason we need this function is that items ware written asynchronously and we don't know the ID ahead of time.

Finally, no it won't work with Cancel. You'll have to alter the behavior of that button.

M.