2

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:

https://mysite/sites/hhc/finance/ap/Lists/APInvoiceForm/EditForm.aspx?ID=76&Source=/sites/hhc/finance/ap/

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

2
+50
  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

    <script>
    function PreSaveAction() {
        var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
    
        if (inDesignMode == "1")
        {
            // page is in edit mode
        }
        else
        {
            // 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;
        }
    
    }
    </script>
    

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.

3
  • Thanks! I'll take a look at this and let you know how it goes.
    – cbbrown
    Commented 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. Commented 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
    Commented Nov 25, 2019 at 9:34
1

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

4
  • 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
    Commented 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
    Commented 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
    Commented 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
    Commented Mar 21, 2017 at 2:29

Your Answer

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

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