cancel
Showing results for 
Search instead for 
Did you mean: 

Update document properties when a new version is uploaded

crono40
Champ on-the-rise
Champ on-the-rise
Hello,

I would like to update document description only when user upload a new version of a document.

I don't know which file i have to modify, I suppose create-new-version.get.js but i'm not really sure.

Could you tell me whick file i have to update to do this ?

Thanks.
8 REPLIES 8

aaditvmajmudar
Confirmed Champ
Confirmed Champ
You can check upload.post.js (/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/upload) file which is responsible to upload new file.

You can check code from line num - 263.

Hope this helps.

Thanks for you reply.

I Tried update this file. I putted this line


updateNode.properties.description = "TEST";


and this one but still not working. Any ideas ?


existingFile.properties.description = "TEST";

aaditvmajmudar
Confirmed Champ
Confirmed Champ
Sorry for the late reply as I was on vacation.

Working now ?

Can you please provide me the line number where you have made these changes?

You are uploading new version of any document from documentlibrary page/document details page.. right ?

crono40
Champ on-the-rise
Champ on-the-rise
No problem Smiley Happy I go on document details page and i go on the right in "actions on document" menu. Next, i click on download new version.  I did the following changes and restart tomcat but the upload still working and nothing change. If you have any ideas… Thanks

I tried this (begin in line 278) in upload.post.js


/**
          * Existing file handling.
          */
         var existingFile = destNode.childByNamePath(filename);
         if (existingFile !== null)
         {
            // File already exists, decide what to do
            if (existingFile.hasAspect("cm:versionable") && overwrite)
            {
           existingFile.properties.description = "TEST"; //Added line !!
               // Upload component was configured to overwrite files if name clashes
               existingFile.properties.content.write(content);
               // Reapply mimetype as upload may have been via Flash - which always sends binary mimetype
               existingFile.properties.content.guessMimetype(filename);
               existingFile.properties.content.guessEncoding();
               existingFile.save();

               // Extract the metadata
               // (The overwrite policy controls which if any parts of
               //  the document's properties are updated from this)
               extractMetadata(existingFile);

               // Record the file details ready for generating the response
               model.document = existingFile;

               // MNT-8745 fix: Do not clean formdata temp files to allow for retries. Temp files will be deleted later when GC call DiskFileItem#finalize() method or by temp file cleaner.
               return;
            }


And the second line here :


if (updateNodeRef !== null)
      {
         /**
          * Update existing file specified in updateNodeRef
          */
         var updateNode = search.findNode(updateNodeRef);
         if (updateNode === null)
         {
            exitUpload(404, "Node specified by updateNodeRef (" + updateNodeRef + ") not found.");
            return;
         }
        
         if (updateNode.isLocked)
         {
            // We cannot update a locked document
            exitUpload(404, "Cannot update locked document '" + updateNodeRef + "', supply a reference to its working copy instead.");
            return;
         }

         if (!updateNode.hasAspect("cm:workingcopy"))
         {
            // Ensure the file is versionable (autoVersion = true, autoVersionProps = false)
            updateNode.ensureVersioningEnabled(true, false);

            // It's not a working copy, do a check out to get the actual working copy
            updateNode = updateNode.checkoutForUpload();
         }

         // Update the working copy content
       updateNode.properties.description = "TEST"; //Line added !!
         updateNode.properties.content.write(content);
         // Reset working copy mimetype and encoding
         updateNode.properties.content.guessMimetype(filename);
         updateNode.properties.content.guessEncoding();
         // check it in again, with supplied version history note
         updateNode = updateNode.checkin(description, majorVersion);

aaditvmajmudar
Confirmed Champ
Confirmed Champ
You can't assign description property directly like this.

Please replace that line with,

existingFile.properties["cm:description"] = "TEST";

Hope this helps.!

crono40
Champ on-the-rise
Champ on-the-rise
It's works ! Thanks a lot Aadit Majmudar Smiley Happy

muralidharand
Star Contributor
Star Contributor
Hi,
Please do not change the javascript files directly and you'll have issues when you're upgrading alfresco version.
So, I would suggest try to use Alfreco folder rules to update the document description.

Please let me know, if you need example for this.

Please, give me example.