Setting up a workflow to automatically export packages on a regular basis (every day, every week for example) can be useful as a back-up procedure. It provides a backup of all parameters in case the database crashes or something is deleted accidentally.
The xtk:spec file contains the specifications. Use a queryDef to load them into JavaScript.
Package specifications loading:
var query = xtk.queryDef.create( <queryDef schema="xtk:specFile" operation="select"> <select> <node expr="@name"/> <node expr="@namespace"/> <node expr="data"/> </select> </queryDef> ) var res = query.ExecuteQuery()
You can also specify the package with an XML document. By default, up to 1000 documents are exported.
To export more documents, set the lineCountMax attribute.
Package specification XML:
<package> <definition id="1" lineCountMax="10000" schema="nms:delivery"> <where> <condition boolOperator="OR" expr="[campaign/@fullName] LIKE '/Campaign Management/%'"/> </where> </definition> </package>
The GenerateDoc() function generates the packages from a specification. It returns an XML object.
Packages export JS:
vars specFileXML = <specFile (...) /> var specFile = xtk.specFile.create(specfileXml) var package = specFile.GenerateDoc()
The package XML needs to be saved to a file and the file name must have the header and the date. The saveXmlFile function writes the contents to a file in XML format.
Save into zip file:
var package = (...) // XML contents of package var fileName = "/tmp/myPackage.xml" saveXmlFile(package, fileName)
If you generate multiple packages, it is more convenient to save all files into a zip file. Files should be located under the "var" subdirectory of the instance and the file name should contain the date.
Save package to zip file:
var zip = new ZipFile(zipfilename) for each (var s in res.specFile) { var packageName = s.@namespace + ":" + s.@name var specFile = xtk.specFile.create(s) var package = specFile.GenerateDoc() package = "<?xml version='1.0' encoding='windows-1252'?>\n" + package var fileName = s.@namespace + s.@name + ".xml" var content = new MemoryBuffer(); content.fromString(package) zip.setEntry(fileName, content) content.dispose() } zip.save("", true) zip.dispose()
To set up the workflow:
- Create a new workflow named Daily export of packages under Administration > Production > Technical workflows.
- Add a scheduler that runs every day.
- Add a JavaScript that exports the packages.
- Run this workflow and monitor its execution.
- A file will be created every day with the contents of the packages.