Suppose you start out with the "Simple Document" document type, but after a while decide you want to switch to your own document type with custom fields and/or parts. You can easily migrate your existing documents to the new document type using a document task. A document task is some task that you want to perform on a set of documents.
To start, make sure you're in the Administrator role.
In the Tools menu, select 'Document tasks'.
Select 'create a new document task'.
If you want to change all your documents, select 'Add documents resulting from a query', and enter the following query:
select name where documentType = 'SimpleDocument'
and press the execute button.
If you want to limit the conversion to the documents in a certain collection, use instead:
select name where documentType = 'SimpleDocument' and InCollection('MyCollection')
The most basic script to change the document type is as follows:
var document = repository.getDocument(variantKey, true); document.changeDocumentType("MyNewDocumentType"); document.save();
However, it might be that you want to initialiase a field to some value, or move the data from one part to another. The listing below shows an example of how to do that. The easiest way to move the data from one part to another would be to move it as a byte array, however a better way is to provide a "PartDataSource", since then everything is done with streams, meaning that it will also work fine for arbitrarily large parts.
See also the javadocs of the repository API (included in the binary Daisy download) for more information on what methods you have at your disposal.
When you're done entering the script, press the Start button.