Get Query String and Set List Form Field Value using jQuery
Now in SharePoint 2010, lets use jQuery to get query string from URL and populate list form field’s value and SharePoint designer Quick Step to pass the query string value to target URL.
Scenario: We’ve a “Projects” list with list of projects, and “Project Metrics” list to capture project metrics.We need to add project metrics to the projects from a context (ECB) menu item from Projects list.
- Lets add a Quick Step using SharePoint designer to pass query string.
- On clicking the Quick Step Link, say “Add Project Metrics”, It navigates to the NewForm URL of Project Metrics list with QueryString “ProjectID”.
- Lets get the query string from URL and set the NewForm’s “Project ID” field of Project metrics list item.
Add a Quick-Step in SharePoint Designer:
Create a new Quick Step in SharePoint designer with “Navigate to URL” selected. Enter the below code in it, to navigate to NewForm.aspx file of Project Metrics list with ProjectID value in URL.
Get Query String and Populate List Form Field Value
In NewForm.aspx of the Project Metrics list, Add a CEWP and link to the below script. Basically, it fetches the Query string “ProjectID” from URL and sets the “Project ID” field in Project metrics list item.
Result: Project ID field is populated from the query string ProjectID from URL
Here is another example I’ve used in SharePoint Online:
9 thoughts on “Get Query String and Set List Form Field Value using jQuery”
what changes should i make in case my url has %3F instead of ? and %3D insead of =
I use $(“input[Title=’1234′]”).removeAttr(‘disabled’);
in PreSaveAction. Everything works fine.
So frustrated 🙂
I can’t seem to get the PreSaveAction to fire in SharePoint 2010 and so the disabled attribute isn’t being unset that I can see as the list item is created but the field set isn’t there
If I comment out the disable attribute line the item goes in as you expect
Is there anyway to prove of ensure the PreSaveAction fires?
Thanks for this – Have been looking for just this type of script. Have tried in in 2013 though it seems to be truncating the value of the query string value sometimes – Have used a value of “This is a test” but am only getting “This is” in the field. Wondering if any known reason for this?
Try wrapping your query string parameter inside characters like “$” and use Split function to get the parameter value. E.g. Instead of ?Param=Value use: ?Param=$Value of the Parameter$.
Great Article!This is similar to the task I am currently working on but in my case I am tasked with populating multiple field values in the relational lists .
Parent list is document library
Child list is just a list that holds ratings based on the document uploaded the document library.
Can you help please?
Thanks a lot! Also works in SP2013 (Online).
Just what I was looking for but I can only get the readonly option to work.
For some reason when disabled, the values aren’t populated into the list. Also, if the fields ARE set to mandatory, the form always asks to fill the mandatory field in, even though populated as if the ‘PreSaveAction’ function isn’t working at all! Any ideas as to why?
When you disable fields, they will **NOT** be populated in the list. You got to enable them back on “PreSaveAction” as I did above. Make sure your code is error free for the presaveaction to fire!