1

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?

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

  • 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 '17 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 '17 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 '17 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 '17 at 2:29
1
+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.

  • Thanks! I'll take a look at this and let you know how it goes. – cbbrown Mar 24 '17 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. – James Grizzle Mar 24 '17 at 13:28

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.