none
redirecting from newform.aspx to another list RRS feed

  • Question

  • Dear Friends,

    The problem i'm facing is-

    When I'm at the newform.aspx page of a list (to add a new item), when I click on save button, the item should be saved in the list and then I should be redirected to another lists' newform.asxp page.

    Can anyone please give me the javascript for this.

    Many many thanks.

    P.S- kindly note that, saving operation needs to be taken care of, before going to next lists' newform. I tried a lot but failed.

    Regards,

    prajK


    Thursday, February 5, 2015 3:23 AM

Answers

  • Hi PrajK,

    Per my understanding, you might want to redirect users to the NewForm.aspx page of another list when clicking the “Save” button in the NewForm.aspx page of the current list.

    You can set a link like this in a view page of List1:

    http://sp/Lists/List1/NewForm.aspx?Source=http://sp/Lists/List2/NewForm.aspx

    Users click this link, they will be redirected to the NewForm.aspx of List1. Input data and click the “Save” button, they will be redirected to the NewForm.aspx of List2, at the meantime, the data input in the NewForm.aspx of List1 has been submitted properly.

    Best regards

    Patrick Liang
    TechNet Community Support

    • Marked as answer by John.P.Smith Tuesday, February 10, 2015 7:11 AM
    Monday, February 9, 2015 7:25 AM
    Moderator
  • Hi,

    Other than using SPServices.js, in your scenario, you can add such an <a> tag into a Content Editor Web Part and insert the web part into the list view page(not the NewForm page):

    <a href="http://sp/Lists/List1/NewForm.aspx?Source=http://sp/Lists/List2/NewForm.aspx">New Item</a>

    When clicking it, it will redirect to the “NewForm.aspx” of List1, fill in the data needed, click “Save”, it will then redirect you to the “NewForm.aspx” of List1.

    Best regards

    Patrick Liang
    TechNet Community Support

    • Marked as answer by John.P.Smith Thursday, February 12, 2015 7:28 AM
    Thursday, February 12, 2015 5:05 AM
    Moderator

All replies

  • Hi PrajK,

    Per my understanding, you might want to redirect users to the NewForm.aspx page of another list when clicking the “Save” button in the NewForm.aspx page of the current list.

    You can set a link like this in a view page of List1:

    http://sp/Lists/List1/NewForm.aspx?Source=http://sp/Lists/List2/NewForm.aspx

    Users click this link, they will be redirected to the NewForm.aspx of List1. Input data and click the “Save” button, they will be redirected to the NewForm.aspx of List2, at the meantime, the data input in the NewForm.aspx of List1 has been submitted properly.

    Best regards

    Patrick Liang
    TechNet Community Support

    • Marked as answer by John.P.Smith Tuesday, February 10, 2015 7:11 AM
    Monday, February 9, 2015 7:25 AM
    Moderator
  • Hello Patrick,

    Thanks for the answer. However I'm curious to know where to write the redirect code? Should I open the NewForm.aspx in designer to write that code? Or on dispform.aspx?

    Monday, February 9, 2015 8:19 AM
  • Hi Patrick,

    Thanks for your response. 

    I have used the "?source" approach already by adding it to a html button. This is one of the solution.

    However what I wanted to know is- how to redirect using javascript/jQuery added in the newform.aspx page. The code that i'm using now isn't working properly. So i was wondering, if someone has got a working js for this.

    Reference: http://spservices.codeplex.com/wikipage?title=%24().SPServices.SPRedirectWithID 

    <script language="javascript" type="text/javascript"> $(document).ready(function() { $().SPServices.SPRedirectWithID({ redirectUrl: "EditForm.aspx", qsParamName: "OrderID" }); }); </script>

    Best Regards

    Tuesday, February 10, 2015 7:25 AM
  • Hi ChandraShekhar,

    You can create a button on your page, and you can use the "?source" approach. On first click it can take you to first list where you want to add your data, and then on click of submit, the "source" can take the user to the next lists' newform.aspx page and so on...

    But if you would like to do it using javascript, as the former is not considered a best practice in SharePoint, then you can edit the newform.aspx page and add the redirection part in your jQuery. 

    Refer these URL's for more and detailed information:

    https://spservices.codeplex.com/workitem/10214

    http://spservices.codeplex.com/wikipage?title=%24().SPServices.SPRedirectWithID

    http://spjsblog.com/2009/09/04/redirect-from-newform-to-editform-or-custom-page/

    http://sharepoint.stackexchange.com/questions/111148/get-list-item-id-from-newform-aspx

    Try it out in SP2013, there is some problem with redirection. I'm not able to figure it out. Let me know if you do.

    Kind Regards

    Tuesday, February 10, 2015 7:30 AM
  • Hi ChadraShekhar,

    You can simply add Content Editor webpart in that NewForm.aspx page and inside the webpart content you can add script tag and your code, its pretty simple..

    Thanks

    Shakir

    Tuesday, February 10, 2015 12:08 PM
  • Hi,

    Other than using SPServices.js, in your scenario, you can add such an <a> tag into a Content Editor Web Part and insert the web part into the list view page(not the NewForm page):

    <a href="http://sp/Lists/List1/NewForm.aspx?Source=http://sp/Lists/List2/NewForm.aspx">New Item</a>

    When clicking it, it will redirect to the “NewForm.aspx” of List1, fill in the data needed, click “Save”, it will then redirect you to the “NewForm.aspx” of List1.

    Best regards

    Patrick Liang
    TechNet Community Support

    • Marked as answer by John.P.Smith Thursday, February 12, 2015 7:28 AM
    Thursday, February 12, 2015 5:05 AM
    Moderator