how to get url parameter value and set those values as a default on a new add item form.

답변됨 how to get url parameter value and set those values as a default on a new add item form.

  • Tuesday, February 28, 2012 3:04 AM
     
     

    Hi All,

    i am trying to achieve url parameter values and set those values on a form automatically. Scenario is i have a custom list. In that list when end user want to add item so they will click + add item link. so when they  will click on add item option javascript query will get parameter values and populated those vales on add new item form automatically. so please let me know which approach will be better for this. Basically i am using sharepoint server 2010 and designer 2010.

    Any help will be appreciated.


    • Edited by rakib1 Tuesday, February 28, 2012 3:05 AM
    •  

All Replies

  • Tuesday, February 28, 2012 4:20 AM
     
     

    you will have to write javascript to read the parameters from the url and using javascript - getElementById('customFieldId') set the values into those fields.

    i use this to get parameters 

    http://www.netlobo.com/url_query_string_javascript.html

    alternative i found this link about a different approach.

    https://www.nothingbutsharepoint.com/sites/eusp/Pages/setting-sharepoint-form-fields-using-query-string-variables-without-using-javascript.aspx


    -tom daly

  • Wednesday, February 29, 2012 3:39 AM
     
     

    Hi Tom,

    Thanks for your reply. i have a url like http://global/test/adm/List/Transactions/AllItems.aspx?Title=Item1&Category=Category1&Price=$500.00 i want to get parameter values by clicking +add new item in the same page. so when i will click on Add new item option in the list, it should populated all parameter values as default on modal dialog box. so please let me know how can i achieve this functionality.

    Any help will be appreciated!


  • Wednesday, February 29, 2012 8:08 AM
    Moderator
     
     Answered

    Hi ,

    I understand that you want to populate the form field to get the value from URL .You can add parameters to get value from the query string
    then set the form field to get the value of the parameters .Here are the detailed steps:

    1. Open the list in SharePoint Designer .Create a new NewForm1 for the list and set the New Form1 as default new form .
    2. Open the NewForm1 in advanced mode .Choose the field which you want to have the value from the URL and delete it .Add a text box in the cell .
    3. Then you can set the text box’s Data Field to the column which you delete .
    4. Choose Parameters under the Options ribbon .Add a new parameter named Param1 .Set the parameter source as ‘Query String ’ .Set the Query string Variable to the name in you URL like Title ,Category, Price .You can also set a default value for the parameter .
    5. In the code view ,find the text box : <asp:TextBox runat="server" id="ff8{$Pos}" text="{@Fieldname}"  __designer:bind=……./> .Change the text to text="{$Param1}" .
    6. Repeating the steps for other fields .Save the new form and preview .

    Thanks


    Entan Ming

    TechNet Community Support

    • Proposed As Answer by Ambaliya Jatin Saturday, March 03, 2012 11:48 AM
    • Marked As Answer by rakib1 Sunday, March 04, 2012 12:58 AM
    •  
  • Wednesday, February 29, 2012 6:46 PM
     
     

    Hi Entan Ming,

    Thanks for your reply.Actually i want to populate modal dialog box form field with url parameter values. lets say when you want to add item on any list, on sharepoint 2010. you will see there is + add new item option, so when you will click on this, it will give you modal dialog box form. Basically i am trying to achive when user will click on +add new item option, modal dialog box form will populate with url parameter values from that page where is +add new item option.

    Any help will be appreciated.

  • Thursday, March 01, 2012 11:18 AM
    Moderator
     
     

    Hi ,

    Do you mean that you want to edit the href of the ‘Add new item ’ link to open in a modal dialog with the url parameters ?

    If so ,you can try this workaround .

    1. Add a content editor web part on the AllItems.aspx page .Add these contents in the content query HTML source :

    <a onclick="javascript:NewItem2(event, 'http://servername/sitename/Lists/listname/NewForm.aspx?Catogory=1'); javascript:return false;" href="http://servername/sitename/Lists/listname/NewForm.aspx?Categoy=1&amp;IsDlg=1" target="_self">Add New Item</a>

    2. You should replace the server name ,site name and list name according to your server configuration .

    3.  Drag the content editor web part below the list view web part .Edit the list view web part ,set the Toolbar as ‘No Toolbar’ .

    4.Modify the new form in SharePoint Designer as steps in my first post.

    Thanks


    Entan Ming

    TechNet Community Support

  • Friday, March 02, 2012 4:18 AM
     
     

    Hello Entan,

    If you look at my pic you will see url has some values. basically i want get those values into modal dialog form field. That means when user will click on +add item, then modal dialog will open and put those values into modal dialog field. i followed your post but my one is not working.  Also you said to Add on click event within the content query HTML source in content editor web part. But url path is not getting correctly, could you Explain little details again so that i can get this functionality.

    Appreciated for your help.

  • Friday, March 02, 2012 10:45 AM
    Moderator
     
     Answered

    Hi ,

    I will list all the detailed steps below :

    1. Open the site in SharePoint Designer .Open the list which you want to customize .
    2. Add a new form for the list named New.aspx . Set the New.aspx  as the default form for the list .
    3. Open the New.aspx in Advanced mode .
    4. Choose the Title form field and delete it .Add a ASP text box instead .Set  textbox’s date field  to Title .
    5. Choose ‘Parameters’ under  the  Options ribbon .Add a new parameter named Param1 . Set the parameter source as ‘Query String ’ .Set the query string variable as Title .
    6. Find the text box field in the code view . Change the text property to text=" {$Param1}" .
    7. You can make changes to the Category and Price column according to step4-step6 .
    8. Save the New.aspx page .
    9. Open AllItems.aspx of  the list in browser .Edit the page and add a content editor web part on the page .
    10. Set the HTML source to the code below : <a onclick="javascript:NewItem2(event, 'http://servername/sitename/Lists/listname/New.aspx? Title=Item1&Category=Category1&Price=$500.00'); javascript:return
      false;" href="http://servername/sitename/Lists/listname/New.aspx?Title=Item1&Category=Category1&Price=$500.00&amp;IsDlg=1"
      target="_self">Add New Item</a>
    11. In this way ,when you click on the Add new item link in the content query web part ,a model dialogue will show up with the URL parameters passed to the form fields .

    Here are some screenshots :

    Thanks


    Entan Ming

    TechNet Community Support


  • Wednesday, March 07, 2012 2:55 AM
     
     

    Hi Entan,

    Hope you are doing well.Thanks for your reply. i have another questions related this post.  I want to read query string value in my pop up page (/document library/forms/Editform.aspx) from parent page url (/document library/forms/AllItems.aspx).

    And then I want to populate this value into a sharepoint form field control.

    Additional Information:

    I have a document library displaying all the items (/document library/forms/AllItems.aspx), uploading a new document by clicking on "Add a new document" -> Poping up a new window (_layouts/Upload.aspx)-> browse the document -> Click on "Ok" -> Poping up a new window (/document library/forms/Editform.aspx) in this page I want to populate one field value with query string value. And I want to read it from parent page(/document library/forms/AllItems.aspx).

    Should i follow your previous post or how can i achieve this. please suggest me that will be greatly appreciated.Could you provide my details step to acheive this functionality?

    Thanks in advance