Using Document Tasks to modify fields in a set of documents
Daisy Tasks can be used to modify a set of documents. This can be done with a "Simple Action" or with a javascript. Simple Actions can modify a document's membership in a collection or create a new variant. Javascript can do anything you can script.
Below are working examples of the javascripts used in a Document Task modify values in fields.
Document Task How-To
- Determine the list of documents to change. This can be a list of IDs or a query
- Click on Document Tasks (in tools menu by default)
- Create a new Document Task
- Enter the document IDs, or click the link to use a Query to add documents.
- Next
- Enter your javascript and choose Start
Test any new javascript with a single document to make sure it functions correctly before running it on a series of documents.
Examples
Updating field based on fixed value
A custom document type Server contains field rack.
Script replaces "4-6" with "4-5" in the field rack.Query for adding documents to Task
select name where documentType='Server' and $rack = '4-6'Javascript with comments to replace 4-6 with 4-5
// Get the current document var document = repository.getDocument(variantKey, true);// Set new field value and save document document.setField("rack", "4-5"); document.save();
Update field based on another field
A custom document type Server contains fields pdu, consoleport and rack.
rack contains values like "4-5"
consoleport contains values like 4/xx (where xx is the console port number)Script takes value of rack and consoleport fields to set pdu to "rack/xx" (example: 4-5/12)
// Get the current document var document = repository.getDocument(variantKey, true);//get field values var con = new java.lang.String( document.getField("consoleport").getValue() ); var rack = new java.lang.String( document.getField("rack").getValue() );//calculate value for pdu var pdu = new java.lang.String( rack + "/" + con.slice(2, con.length() ) );//set new field value and save document document.setField("server_pdu", pdu ); document.save();



There are no comments.