locked
Redirect from Sharepoint NewForm.aspx to EditForm.aspx RRS feed

  • Question

  • Hi all,

    I have 2 sharepoint lists, 'Identify Risk' and 'Analyze Risk'. In Identify Risk List i have fields, Project Number, Risk Id, Risk Category. In Analyze Risk list i have fields, Project Number, Risk Id, Potential Impact.

    My requirement is user open Identify Risk NewForm and enter data. When the user save in Identify Risk, Project Number and Risk Id should go to Analyze Risk List and it should open EditForm of Analyze Risk list automatically, with Project Number and Risk Id.

    I tried this with an EventReciever, but redirecting url to EditForm is not working. Pls help me to do this.

     

    Thanks

     

     

     

    Monday, February 6, 2012 9:35 AM

Answers

  • Hi Mohamedaz

    Thanks for your post, you can use the EventReciever to achieve your requirement. In EventReciever you can  use SPUtility.Redirect to redirect url. Following is my code:

    private HttpContext _currentContext = null;

    public EventHandler1 () : base ()

    {

         if(null!= HttpContext.Current)

         {

             _currentContext = HttpContext.Current;

         }

    }

    public override void ItemAdding(SPItemEventProperties properties)

    {

         using(SPSiteFormSite = newSPSite("http://lhan-pc1:8081/sites/sites1"))

         {

             using(SPWebFormWeb = FormSite.OpenWeb())

             {

                 SPListLookupList = FormWeb.Lists["list1"];

                 SPListItemCollectionReturnedItems = LookupList.Items;

                 if(ReturnedItems.Count > 0)

                 {

                     SPUtility.Redirect(string.Format("EditForm.aspx?ID={0}", ReturnedItems.Count+1), SPRedirectFlags.Trusted, _currentContext); 

                 }

             }

         }

         base.ItemAdding(properties);

    }

    Thanks,

    Lhan Han

    • Marked as answer by Lhan Han Sunday, February 12, 2012 6:19 AM
    Tuesday, February 7, 2012 11:09 AM
  • Hi Mohamedaz

     

    If you want to open the EditForm.aspx of another list, you must obtain the item id of the other list you want to edit. You can get the value of the fields (Project Number, Risk Id) by:

    currentContext.Request.Form[controlName]

    How to get the controlName: Use IE developer tools to look over the control name and get it.

    Then you can compare the values with the edit list, and find the id. Finally use the above code to achieve your requirement.

     

    Thanks,

    Lhan Han

    • Edited by Lhan Han Wednesday, February 8, 2012 3:04 PM
    • Marked as answer by Lhan Han Sunday, February 12, 2012 6:19 AM
    Wednesday, February 8, 2012 3:02 PM

All replies

  • Can you please let me know the approach you are using to achieve this?

     

     


    SachinKumar
    Monday, February 6, 2012 12:59 PM
  • Create a custom page and add custom list form of Identify Risk new form. Remove the "Ok" button add sharepoint form action button. create custom action as 1st step and create item in both the list using form action workflow. then use " navigate to page" action and put path of edit form of analyze risk and id as querystring.
    Tuesday, February 7, 2012 7:03 AM
  • Hi Mohamedaz

    Thanks for your post, you can use the EventReciever to achieve your requirement. In EventReciever you can  use SPUtility.Redirect to redirect url. Following is my code:

    private HttpContext _currentContext = null;

    public EventHandler1 () : base ()

    {

         if(null!= HttpContext.Current)

         {

             _currentContext = HttpContext.Current;

         }

    }

    public override void ItemAdding(SPItemEventProperties properties)

    {

         using(SPSiteFormSite = newSPSite("http://lhan-pc1:8081/sites/sites1"))

         {

             using(SPWebFormWeb = FormSite.OpenWeb())

             {

                 SPListLookupList = FormWeb.Lists["list1"];

                 SPListItemCollectionReturnedItems = LookupList.Items;

                 if(ReturnedItems.Count > 0)

                 {

                     SPUtility.Redirect(string.Format("EditForm.aspx?ID={0}", ReturnedItems.Count+1), SPRedirectFlags.Trusted, _currentContext); 

                 }

             }

         }

         base.ItemAdding(properties);

    }

    Thanks,

    Lhan Han

    • Marked as answer by Lhan Han Sunday, February 12, 2012 6:19 AM
    Tuesday, February 7, 2012 11:09 AM
  • Hi Sachin Dagar,

    Basicaly my requirment is the user wanted to enter data in 2 different forms. Thats why i created 2 lists, Identify Risk and Analyze Risk. The part of the data is entered to Identify Risk list and rest is in Analyze Risk list. Im trying to allow user to enter data in Identify Risk Newform.aspx page initially, the values are Project Number, Risk Id, Risk Category. Once he clicks save button, he needs to go to data entry page of Analyze Risk list automatically, with Project Number, Risk Id already added.

    Because the user no need to Project Number and Risk Id in both forms.

    I tried with a event reciever item added method. Here i adding the values to Analyze Risk list and trying to open EditForm.aspx with query string of ID.

    Thanks

    Wednesday, February 8, 2012 5:26 AM
  • Hi Anupam Ujjwal,

    Can you little bit explain your approch further. I ddnt understand where this workflow comes.

    Thanks.

    Wednesday, February 8, 2012 5:29 AM
  • Hi Lhan Han,

    Your code is working, but i wanted to open the EditForm.aspx of another list. And it opens the EditForm.aspx but the

    current values are not added.


    Thanks
    Wednesday, February 8, 2012 5:30 AM
  • Hi Mohamedaz

     

    If you want to open the EditForm.aspx of another list, you must obtain the item id of the other list you want to edit. You can get the value of the fields (Project Number, Risk Id) by:

    currentContext.Request.Form[controlName]

    How to get the controlName: Use IE developer tools to look over the control name and get it.

    Then you can compare the values with the edit list, and find the id. Finally use the above code to achieve your requirement.

     

    Thanks,

    Lhan Han

    • Edited by Lhan Han Wednesday, February 8, 2012 3:04 PM
    • Marked as answer by Lhan Han Sunday, February 12, 2012 6:19 AM
    Wednesday, February 8, 2012 3:02 PM
  • Take a look at SPServices.  It includes a call to "...redirect to a another page from a new item form with the new item's ID. This allows chaining of forms from item creation onward."

    http://spservices.codeplex.com/wikipage?title=$().SPServices.SPRedirectWithID&referringTitle=Documentation

    Thursday, February 9, 2012 1:44 AM