Monday, May 21, 2012

Crafting your own document upload form

Extranet 5.6 introduced some nice enhancements to how documents are presented, including the ability to avoid the use of the standard document form altogether. Not forcing the user to use a popup window when all they want to do is upload a document is a nice improvement, but what if you really want to collect additional data that describes the document? You could certainly use the standard document form, but if the meta-data you wish to collect is different than the information collected on that form, what do you do?

Make your own document form, of course!

Let me show you how…

Step 1: Create your own document wrapper
If we wish to collect meta data about the uploaded file that is different than the data collected on the standard document upload form, we’ll need a place to store that data. This is simple enough to do by creating a new CDT. For our example, we’ll name the CDT “Attachment”.

image

The attachment should define attributes the represent the data you wish to collect form the user. There aren’t really any restrictions here. You can see that, in our example, we’re wanting a place to collect an optional display name for the document, an optional version, and a a few other flags. The only required attribute would be a reference to a Document which is where we’ll store the uploaded file. By creating the attribute as an Entity of Document, we’ll be still be able to take advantage of the native versioning capabilities of Click Portal.

Step 2: Define your upload form
Now that we have a place to store the custom document metadata, we need a way to collect it from the user. Accomplishing this is a simple matter of defining a view for the CDT.

image

This view can look however you want. The only critical element of the form is to provide the means for the user to upload the document. The document upload view control is set to “File Upload/View”.

image

Step 3: Update the attributes on the Document entity
Though not required, if you wish to allow the user to provide their own display name, description, or version for the document, you can collect it in your CDT View then, via the view validation script, you can copy those values to the reference document entity. This is important because when the document entity is displayed in the site, Click Portal will automatically use the Document.name and Document.version attributes to present the hyperlink to the document. Here’s a sample based upon our example:

   1: var newDocName = targetEntity.getQualifiedAttribute("customAttributes.tempName");



   2: if(newDocName != null)



   3: {



   4:     targetEntity.setQualifiedAttribute("customAttributes.draftVersion.name", newDocName)



   5: }



   6: //Setting of new version number after verifying it isn't empty.



   7: var newVersion = targetEntity.getQualifiedAttribute("customAttributes.userVersionNumber");



   8: if(newVersion != null)



   9: {



  10:     targetEntity.setQualifiedAttribute("customAttributes.draftVersion.version", newVersion)



  11: }






This is just a sample. You can use this technique for any of the attributes on the Document entity.



That’s really all there is to it. With this technique, you can continue to leverage the power of Document, which provides automatic document versioning, while presenting your own document upload form. You could even take it a step further by exposing the standard document history link in your views with a bit of extra coding. Whenever you need this presentation of a document upload for, you define a custom attribute that refers to this CDT.



Simple as 1,2,3.



Cheers!

No comments:

Post a Comment