Website Downloads Documentation Knowledgebase Wiki Issue tracker Commercial support

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

  1. Determine the list of documents to change.  This can be a list of IDs or a query
  2. Click on Document Tasks (in tools menu by default)
  3. Create a new Document Task
  4. Enter the document IDs, or click the link to use a Query to add documents.
  5. Next
  6. 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();
Comments (0)
Advertisement

Daisy hosting, installation, support. Workshops and turnkey Daisy CMS projects. Get Daisy from its creators.

outerthought.org

Downloads provided by

SourceForge.net Logo

Open source stats