You can already find this process on other sites around the web, but it was only in a comment I found out that this only works with default forms (and not with custom made forms created by you). This is why you need to edit NewForm.aspx, DispForm.aspx or EditForm.aspx.

Also, to be able to use this you must be a Site Collection administrator.

This is done using prototype.js and SPUtility.


Editing the file in Advanced Mode, insert this code right below this line:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

First, we include the two javascript files. I created a folder inside my site named JS and put them inside, but you can upload them anywhere you want.

<script type="text/javascript" src="/JS/prototype.js"></script>
<script type="text/javascript" src="/JS/SPUtility.js"></script>

Next, the script.

<script type="text/javascript">
// this gets the value from a url parameter (?parameter=value)
function GetValueFromURL(queryParamName) {
    var queryParams = location.href.toQueryParams();
    if (queryParams != null && queryParams[queryParamName] != null) {
        return decodeURI(queryParams[queryParamName]);
    }
    return null;
}

Event.observe(window, 'load', function() {
    try {
      // url_parameter is the parameter you are looking for
      var urlValue = GetValueFromURL('url_parameter');
      // field_name is the label of the field you want to fill in
      SPUtility.GetSPField('field_name').SetValue(urlValue).MakeReadOnly();
    } catch (ex) {
      alert(ex.toString());
    }
});
</script>

And this is it. Thanks to SPUtility, this works for text fields, dropdown menus and more.

References:
Autopopulate a SharePoint Form from URL (with SPUtility.js)

Leave a Reply

Your email address will not be published. Required fields are marked *