I'm using SharePoint 2010. My SharePoint is set up with a single document library. All the documents have metadata and pages display metadata-filtered views onto the doc library. So far so good, the same document can appear on multiple pages and I've escaped from folder-land.

Except... when a user uploads a document via a page I want the default metadata to be automatically populated from the view filter, thus the doc actually appears on the page and users have a reasonable experience. Ideally users would be able to add more metadata at the same time, i.e. the dialog pops up pre-populated, user completes, done.

Is there a way to make this happen with OOTB functionality, or at all (I'm a reasonably handy programmer, not yet tried in SP though)

All advice gratefully received (including 'that approach is never going to work'...)

  • You could have have some metadata fields mandatory, so when a user uploads the document it remains checked out until user fills up the metadata and check the document in. As such the user would automatically get the document edit form by SharePoint to fill up the data.
    – Nisarg
    Apr 3 '16 at 3:09
  • Tell a bit more about this Page. Are there query parameters you need to Pass to the document properties? Apr 3 '16 at 21:30
  • @Nisarg - I've got that set up, but users have no way of knowing what metadata to add to make sure the doc appears in that view. Even if they did they'd have to manually enter the metadata which falls short of the user experience I want to deliver.
    – Jason G
    Apr 4 '16 at 9:27
  • @Jan Jouke - I don't think I'm using a query at the moment, just filtering a view using metadata. Is it possible to pass query parameters to both the view and the default upload document properties?
    – Jason G
    Apr 4 '16 at 9:28
  • 1
    Hi @JanJoukeTjalsma, still picking my way through it amid a load of distractions and putting myself through a crash course in jscript & programming SP! Thanks for checking in, will let you know when I've got something working or get properly stuck.
    – Jason G
    Apr 15 '16 at 17:15

I have done something similar in the past and created a proof of concept for you using some of the ideas.

The below code sample is meant to be added to the editForm (ideally a newForm) using something like a content editor webpart. It works with a text field where the internal name equals the display name (so basically any newly created text field).


<!-- This should be added to a newForm in SP2010 -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.2.min.js"></script>
<script type="text/javascript">
  //Get the query parameters (inlcuding the filters)
  var parentString     = window.parent.location.search;

  //Get the filters
  var queryParams   = parentString.replace(/(^\?)/,'').split("&").map(function(n){return n=n.split("="),(n[0].indexOf('Filter') ===0 ? this[n[0]]=n[1] : false),this;}.bind({}))[0];

  //Apply the filters

    //Process only the FilterField items
    if(prop.indexOf("FilterField") === 0){

      //Remove the word FilterField from the prop name to get the filter index
      var filterIndex = prop.substr(11);

      //Get the value for this filter index
      var fieldValue = queryParams['FilterValue'+filterIndex];

      //Find the formfield belonging to the filter
      var field = jQuery("input[title^='"+fieldName+"']");

      //Set the value of the field to the filtervalue


The basic idea is that you can get the filters from the address bar.

Some of the issues with this code:

  • This does not work for builtin fields (they have a different name in filter and in form)
  • This should be added to a newForm, not an editForm. Problem is that you don't have a newForm with metadata in a document library, only an editForm. So to prevent it from overwriting your values every time you edit the metadata you should check for that.
  • It only works with popups
  • It probably only works for text inputs as it is now
  • Strings should be URL-decoded (easily fixed)
  • @ Jan Jouke this looks pretty useful. I need to get hold of SharePoint Designer or get it enabled, then will give it a go and let you know what happens. Thanks!
    – Jason G
    Apr 5 '16 at 11:28
  • Hi @Jason you don't really need SP designer for this. You can add a webpart by going to the URL of your form then edit the page using the ribbon. See: imgur.com/QHFkIkI Apr 5 '16 at 14:14
  • @ Jan Jouke I've spent some time trying to understand the code but am failing. It seems to fall down where it tries to get the filters (I've got a filter in my URL). You're mapping with what I think is a recursive anonymous function, with a return statement followed by a conditional operator statement, then 'this', all separated by commas. From reading about JScript the comma operator evaluates all operands and returns the last, so the function would return 'this', which would be itself. Am i right? This has melted my brain a bit, but is more than likely my lack of experience with SP/JScript.
    – Jason G
    Apr 27 '16 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.