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!