cancel
Showing results for 
Search instead for 
Did you mean: 

CheckIn using new file

tomoconnell
Champ in-the-making
Champ in-the-making
Using the CheckIn/CheckOut API in javascript from a workflow definition, can you somehow specify a file to use as the new version on checkin.
6 REPLIES 6

parzgnat
Star Contributor
Star Contributor
I think you have two options with the Alfresco API.

Option 1:  Use the CheckOutCheckInService to check out the node, which will give you the noderef of the working copy.  Then set the content of the working copy to be your new file.  Finally, use the CheckOutCheckInService again to check in the working copy of the document that you just modified.

Option 2:  Use VersionService to create the new version of your document.  Then set the content of the document to be your new file.

tomoconnell
Champ in-the-making
Champ in-the-making
Thanks for the reply.

Before I created this thread I tried option 1. I'm converting word docs to pdfs, and then using that pdf to overwrite the old pdf. Unfortunately when I set the content of the pdfs working copy, the checked in content just comes up blank. It keeps stuff like the amount of pages that should be there.

                      var workingCopy;
                      var tempNode = node.transformDocument("application/pdf", tempDest);
                      workingCopy = oldNode.checkout();
                      workingCopy.content = tempNode.content;
                      workingCopy.checkin("Review acceptance, updated to new ver");


Sorry if that's confusing out of context.

niketapatel
Star Contributor
Star Contributor
Hi Tom,

You need to write content  -
workingCopy.properties.content.write(tempNode.properties.content);



var workingCopy;
var tempNode = node.transformDocument("application/pdf", tempDest);
workingCopy = oldNode.checkout();
//workingCopy.content = tempNode.content;
workingCopy.properties.content.write(tempNode.properties.content);
workingCopy.checkin("Review acceptance, updated to new ver");


Please check - http://wiki.alfresco.com/wiki/4.0_JavaScript_API


"<strong>content </strong>
The text content of the node can be modified by setting this property. For example mynode.content = mynode.content + "append some text";. This is very powerful as it allows the content of a node to changed from within a script. However it is not recommended that nodes with binary content are manipulated in this way. If you want to update binary content, you can use the write()-method, e.g.: document.properties.content.write(otherDocument.properties.content);"

tomoconnell
Champ in-the-making
Champ in-the-making
I got the content.write to work and thats all fine, apart from now when it checks it in it is just overwriting the file, it will always now be version 1.0.

Edit, sorry forgot the code
once again, sorry for out of context variable names.


                         var tempNode = node.transformDocument("application/pdf", tempDest);
                         var workingCopy = oldNode.checkout();
                         workingCopy.properties.content.write(tempNode.properties.content);
                         workingCopy.checkin("Review acceptance, updated to new ver");
                         tempNode.remove();                         

niketapatel
Star Contributor
Star Contributor
Tom,

Please try this, Need to use this API - checkin(String history, boolean majorVersion)

 workingCopy.checkin("Review acceptance, updated to new ver" , true); 
//checkin with major version increment

This api - "Performs a checkin operation on a working copy node, applying the specified version history note text and as a major or minor version increment as required. Returns the original node that was previously checked out."