Groovy Updater Script Examples
On this page
Examples
Example 1 : Add a property
The following updater script example adds a property gettingstarted:copyright to all documents of type gettingstarted:newsdocument. The script would be useful in the following situation:
- Create a new project from the archetype.
- Create some news documents.
- Modify the gettingstarted:newsdocument type and add a String field called 'copyright' with default value "(c) BloomReach".
- Commit the type.
- Create some more news documents.
All newly created news document will now get the 'copyright' field with the default value "(c) BloomReach". However, existing news documents still have an empty 'copyright' field, and need to be updated. The following updater script will add the default copyright statement if it does not exist. It will also undo the operation.
After the updater script is executed, all existing news documents will have the default copyright value too. When the script is undone, the default copyright value will be removed again from only those news documents that were changed by the updater. The other news documents will not be touched.
XPath query
Groovy script
Example 2: Update HST configuration to replace deprecated hst:content node
In Bloomreach Experience Manager 7.8.x, the HST deprecated the hst:content node below hst:site nodes. Instead of a hst:content node of type hippo:facetselect with a hippo:docbase containing UUID of root site content, the HST now supports instead a property hst:content on the hst:site node containing the absolute jcr path. To replace all hst:content nodes by this hst:content property, the following example Groovy script can be run: