This page outlines the process to clone a record. This is the method that is used for creating Self-Submission records based of a Data Management Plan (version 1.6.1 or later) but could just as easily be used to clone records of the same type.
Essentially what we are trying to do is create a new record (i.e. with a new identifier), copy the metadata from the original (the source) and (optionally) transform the metadata to clean up things that you may want to be unique in your new record (e.g. the title field).
Adding cloning to the user interface
To add cloning to the user interface we need to register an on click event that makes 2 ajax calls. The first calls our packaging script which will create a new package (record) of the type we require and returns it's identifier. On successful completion of the packaging script, we call our copyTfPackage script to copy the metadata from our source package into the newly created package and sets an additional property that can be used to flag that a transform is required.
The key things that you may need to change from the above code snippet are the packageType and the tfMetaPropertyValue. The relatedData property tells the copyTFPackage script whether to write information about it's source record, if this is used in the Data Management Tool to show what related self-submission records have been created but will break if used with the standard review (Dataset) record. If you are using it with the review record, set relatedData to "false".
Configuring the transform
We utilise ReDBox's transformer functionality to modify the newly cloned data. As we store our metadata is stored as JSON, we utilise our JSON Velocity Transformer to do the job. First we need to set up the transformer by adding the following to the transformerDefaults in our system-config.json:
We also need to associate this transformer to our record type. This is done in the packages rules configuration file:
The transform template
The final piece to the puzzle is the transform template. This is a velocity template that will produce a JSON output based on the data that is in the original metadata (that is loaded into a context object by the transformer). Snippet below is a cut down example of the transformer specified in our system-config.json, for a more complete example checkout the version in github: