I am trying to use the Source QueryString Parameter once the user makes changes to the Edit Form.

Here's the Source URL I am using:


I paste it into the URL, hit enter, and it will work the first time when you press save, but every other time after, it defaults back.

Is this not possible to use with the Edit Form?

2 Answers 2

  1. Open your Newform.aspx or Editform.aspx page.

  2. Add a Script Editor Web Part. Type following line in your site url

New Form: http://YOUR_SERVER/Lists/YOUR_LIST/NewForm.aspx?&toolpaneview=2

Edit Form: http://YOUR_SERVER/Lists/YOUR_LIST/EditForm.aspx?&toolpaneview=2

  1. Paste below script in the script editor webpart

    function PreSaveAction() {
        var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
        if (inDesignMode == "1")
            // page is in edit mode
            // page is in browse mode
            var srcUrl=GetSource();
            var newSrcUrl = "&source="NewSource.aspx";
            var i = aspnetForm.action.lastIndexOf(srcUrl);
            aspnetForm.action = aspnetForm.action.substring(0,i) + newSrcUrl ;
            return true;

Sorry I can't test this out right now, you might have to play with the URL or JavaScript to get this to work properly. &source="NewSource.aspx" might be ?source="NewSource.aspx", the difference is that ? is for the first query string parameter and & is for any subsequent parameters. This post has a ton of ways to check if the page is open in JavaScript. I'm not sure which one will work with Office 365.

  • Thanks! I'll take a look at this and let you know how it goes.
    – cbbrown
    Mar 24, 2017 at 13:15
  • If your presaveaction code works, you can just use that, I think you only really need the inDesignMode part from my script. Mar 24, 2017 at 13:28
  • good solution. But searching for last index of srcUrl did not work for me. Instead I used last index of 'Source='.
    – Sagar
    Nov 25, 2019 at 9:34

When you come to edit page, you have to pass source parameter, if parameter is missing you can write JavaScript to include that parameter if it is missing. more detail here

  • So, can you not just add the source to the edit form, or do you have to add it to the New Form? The reason I ask is because I have different people using the form and only the Edit form would need to redirect. Thanks!
    – cbbrown
    Mar 17, 2017 at 12:17
  • JavaScript is better because if any for any reason source is not present is URL, you can add through JavaScript and it will make sure source parameter is always available event if user directly type the edit form url.
    – Ali
    Mar 18, 2017 at 8:46
  • 1
    Would PreSaveAction function be the best thing, or is there another script that would be better? I'm sorry. I'm very new to JavaScript and looking for resources.
    – cbbrown
    Mar 20, 2017 at 10:43
  • add on load, if source parameter exists then well and good, if does not exist, add that missing parameter and refresh page.
    – Ali
    Mar 21, 2017 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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