When users upload files to a SharePoint Online (2013) document library, I would like for a value from the query string to be inserted into a metadata column in the library.
I found a number of posts that suggest editing upload.aspx, but this is not possible in SharePoint Online / Office 365.
I'm able to intercept upload.aspx and set the "Check in Comments" field to the value in a query string parameter "projectid" by adding the following code to the bottom of a copy of the master file:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
if (window.location.href.toLowerCase().indexOf('/_layouts/15/upload.aspx') > 0 || window.location.href.toLowerCase().indexOf('/_layouts/15/uploadex.aspx') > 0)
{
JSRequest.EnsureSetup();
var projectid = JSRequest.QueryString["projectid"];
$("#ctl00_PlaceHolderMain_VersionCommentSection_ctl01_CheckInComment").val(projectid);
}
});
</script>
For example, I can load the url
https://[sitename].sharepoint.com/sites/theocean/_layouts/15/Upload.aspx?list=%7b233fd992-5f7e-427d-9e57-9947b5b37447%7d&rootfolder=&isdlg=1&projectid=p123 and the "Version Comments" (a.k.a. "Check In Comments") field will be automatically set to "p123".
However, with this approach, I'm running into the following limitations and am not sure how to work around them:
- This does not work for "drag and drop". How can we intercept uploads and set a metadata value when users drag files to the document library panel?
- I'm setting the "Check In Comments" column only because it's available on Upload.aspx, but I really want to set a custom "Project ID" column. Is there a way to do this?
- When loading a url as above with a query string parameter, I'm able to successfully upload the file, but I get a message "This shouldn't take long," but it sits forever on that page. How can I automatically chain from the upload page to the document library page after the upload completes?
I've tried using SPUtility.js, but that apparently works only for NewForm.aspx and EditForm.aspx. In Upload.aspx, calling SPUtility.GetSPFields() returns nothing.