1

I used below code in my online sharepoint(2016) project. While the redirect part is working perfect, the new item, however, is not saved. May I ask, did anyone ever get the same issue like this? Here is the script I used:

<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () { 
    var button = $("input[id$=SaveItem]");
    // change redirection behavior
    button.removeAttr("onclick");
    button.click(function() {
        var elementName = $(this).attr("name");
        var aspForm = $("form[id='aspnetForm']");
        var oldPostbackUrl = aspForm.get(0).action;
        var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);

        var issueID = getCookie("myID");
        var redirectPage="/Lists/PM2/DispForm.aspx?ID="+ myID;
        var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, redirectPage);

        if (!PreSaveItem()) return false;
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
    });
});
</script>

I have tried many different workarounds...for some approches, after click save button, the data is saved, but page goes to 'AllItems.aspx', not the one I specified; for other approches, after click save button, page redirect to my specified one successfully, but data not saved..none approach works for both redirecting and saving. Any ideas? Please help! Thank you!

  • Same boat. Using this code, and similar old variations, I can save or redirect, but not both. Will be following this question to see if anyone has figured out how to do this recently in sp online. – BDC604 Apr 13 at 5:22
0

I recently got a solution, by define save button as: var button = $("input[value='Submit']"); and in PreSaveAction() using: window.history.pushState('displayform', 'displayform', newPostbackUrl);

This works for both redirect and save part. Hope this can help you too. I am still not sure why so though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.