Set list item field in URL
-
06-01-2021 - |
Question
Let's say I have a list with three fields:
- Title
- Description
- Type (dropdown)
Via the URL, would it be possible to set the value one of the fields?
for example,
https://.sharepoint.com/Lists/Test/NewForm.aspx?title=SetTheTitle
and it sets the value of the Title field to "SetTheTitle"? I know this could be accomplished with JS, but is there a built-in way?
La solution
You can use the URL to filter items that have been created. You can also set a query string parameter for different uses like retrieving it to hide or show different fields (i.e. ?Department=HR) and setting fields.
So, given that, you could set a field to a value if the query string equals a certain value.
This can be accomplished (as an example), by using the JSRequest object.
Given your URL https://.sharepoint.com/Lists/Test/NewForm.aspx?title=SetTheTitle, you could use:
JSRequest.EnsureSetup();
var queryString = JSRequest.QueryString["SetTheTitle"]; // queryString = "SetTheTitle"
Then
if (queryString === "SetTheTitle") {
$(#MyFieldToSet).val("The query string set this field");
}
Something along those lines...
As far as I know, there is no way to set the value of a field from the URL only, as you would need a mechanism to do so, like REST, CSOM, etc.
I hope that makes sense.