Question

When a user uploads/creates a document into my document library, i need to be able to apply a metadata tag to the document either from the URL query string or from the value selected in some web-part that is also on the page.

Here is the full explanation: I want to build a web-part that reads from a list and presents a hierachical navigation tree, the bottom level nodes will map to terms in the term-store and will be links to document libraries. Multiple bottom level nodes can point to the same library. When a user clicks a bottom level node they are taken to the relevent library for that node, when they create/upload a document the appropriate metadata term (that they clicked on in the navigation tree) will be applied to the document (they can't then change it).

Does anyone have any ideas how this might be done? I thought of adding a query string to the URL but not sure how to then apply the term to the item.

I also thought of creating a custom field that would be applied to the content type of the documents being uploaded but i don't think that the code in the field would be able to 'reach' up onto the page to grab the selected value from the navigation control or get it from the URL either.

Finally i thought of an event receiver on the doc library, but again i'm not sure how to obtain the term that needs to be applied to the document,

Any help would be appreciated,

Thanks

Was it helpful?

Solution

If you want to use query string parameters to set metadata, you're going to need some script that parses the query string and sets the field values. I've done this in the past with jQuery and SPServices. Marc has created a dead simple to use query string parser in the SPServices project.

Here's an example from a project I worked on that got 2 query string variables and set field values with them.

<script type="text/javascript">
$(document).ready(function(){

var queryStringVals = $().SPServices.SPGetQueryString();
var IDtoGet = queryStringVals["theCID"];
var insEmail = queryStringVals["InstructorEmail"];
  $("textarea[Title$='People Picker']").val(insEmail);
  $("div[title='People Picker']").text(insEmail); 
}); //close doc ready
</script> 

OTHER TIPS

As @PirateEric mentioned, an easy way to set metadata fields using a query string is by using JavaScript. I maintain SPUtility.js which can help with setting and getting SharePoint fields. For example:

SPUtility.GetSPField('Document Category').SetValue(urlValue).MakeReadOnly();

You probably won't be able to use an event receiver because it won't have access to a query string parameter (see How to retrieve the querystring in Sharepoint itemadded event).

See also: Autopopulate a SharePoint Form from URL (with SPUtility.js) (my blog)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top