Skip to main content

Groovy Script - Update Namespace Property Attributes in DOCX and XLSX Files

Description:

  • Sample Groovy script to Update Namespace Property Attributes in DOCX and XSLX files of the current document.

  • This script should be directly used with Trigger and within the visual workflow service task.

Context: Document


​Remark: Accessible in Post task mode only.

Script:

def execute() {
FileAttributesVO fileAttributesVO = new FileAttributesVO ();
HashMap<String,HashMap<String,String>> nameSpaceAttributeMapping = new HashMap<>();
HashMap<String,String> attributeMapping = new HashMap<>();
attributeMapping.put("Discipline1","dc:title");
attributeMapping.put(IDocumentAttribute.REV,"Revision"); //standard attributes
attributeMapping.put("ProjectName","ProjectName");
nameSpaceAttributeMapping.put("http://schemas.openxmlformats.org/package/2006/metadata/asite-test", attributeMapping);
fileAttributesVO.setNameSpaceAttributeMapping (nameSpaceAttributeMapping);

// This map contain namespace as key and template name as a value. ex.. key=namespace Name value= template Name
Map<String, String> nameSpaceTemplateMap = new HashMap<>();
nameSpaceTemplateMap.put("http://schemas.openxmlformats.org/package/2006/metadata/asite-test","template.xml");
fileAttributesVO.setNameSpaceTemplateMap(nameSpaceTemplateMap);

documentService.writeAttributesInFile(fileAttributesVO);
}
Did this answer your question?