0

The below code will redirect to the correct page. but the list is not saved.

 $(document).ready(function() {
        var button = $("input[id$=SaveItem]");
            button.removeAttr("onclick");
                button.click(function(event) {
                if (!PreSaveItem()) return false;
                var elementName = $(this).attr("name");
                var aspForm = $("form#aspnetForm");
                var oldPostbackUrl = aspForm.get(0).action;
                var newPostbackUrl = _spPageContextInfo.webAbsoluteUrl;
                if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true)) 
                return false;
            });
    });

suggest an idea to resolve this issue.

  • what is the SharePoint version ? where I tried this before in 2013 ad not working ?! – Mohamed El-Qassas MVP Dec 10 '16 at 10:13
  • I have tried it in Sharepoint 2013. @M.Qassas – PGP Dec 10 '16 at 10:17
  • Please Check my answer , that will match your requirements in SP 2013 , tell us the result :) – Mohamed El-Qassas MVP Dec 10 '16 at 12:28
1

I hope It will work for you

$(document).ready(function() {

var button = $("input[id$=SaveItem]");
// change redirection behavior
button.removeAttr("onclick");
button.click(function() {
var elementName = $(this).attr("name");
var aspForm = document.forms['aspnetForm'];
var oldPostbackUrl = aspForm.action;
var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
  var newPostbackUrl1 = _spPageContextInfo.webAbsoluteUrl;

var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue,newPostbackUrl1 );

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

});
2

Try the following workaround

  • Open AllItems.aspx page
  • Edit Page > Add Script Editor
  • Add this code

[Code]

 <script>   
 function RedirectAfterSave() {
    document.getElementById("idHomePageNewItem").removeAttribute("onclick"); 
    document.getElementById("idHomePageNewItem").href="http://epm/workflow/Lists/Shoe%20Models/NewForm.aspx?Source=http://epm"; 

    }

    _spBodyOnLoadFunctionNames.push("RedirectAfterSave");
   </script>

Note :

At document.getElementById("idHomePageNewItem").href= put your link to NewForm page before Source Query String and after it add your Custom Page URL that you want to go back.

  • It's not working @M.Qassas – PGP Dec 10 '16 at 12:48

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.