Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Read data from custom XML parts of .docx file and set attribute values in File Upload screen
Groovy Script - Read data from custom XML parts of .docx file and set attribute values in File Upload screen
Updated yesterday

Description: Sample groovy script to read data from custom XML parts of .docx file and set attributes in File Upload screen.

Context: Document

Remark: Accessible in 'On-Load' task mode only

Script:

def execute(){

JsonArray attributeDetailsList = new JsonArray();

DocumentVO document = documentService.getDocumentDetails();

attributeDetailsList.add(getAttributeJSON(IDocumentAttribute.REV, IDocumentAttribute.STANDARD, IDocumentAttribute.READ_ONLY,"Revision")); // Params: Attribute Name, Type Of Atribute, Editable/Read Only

attributeDetailsList.add(getAttributeJSON("Signatory Department", IDocumentAttribute.CUSTOM, IDocumentAttribute.READ_ONLY,"AuthorDepartment"));

attributeDetailsList.add(getAttributeJSON("My Classification", IDocumentAttribute.CUSTOM, IDocumentAttribute.READ_ONLY,"Classification"));

document.setResponseStatus(false);

document.setDynamicObject(attributeDetailsList.toString());

return document;

}

// This is a generic method to prepare JSON object. No need to do any change in this method.

private JsonObject getAttributeJSON(String attributeName, boolean isCustomAttribute, boolean editOption, String propertyName) {

JsonObject attribute = new JsonObject();

attribute.addProperty("attributeName", attributeName);

attribute.addProperty("isEditable", editOption);

attribute.addProperty("isCustomAttribute", isCustomAttribute);

attribute.addProperty("filePropertyName", propertyName);

attribute.addProperty("ruleApplyToFileFormat", "docx");

attribute.addProperty("readAttributeValueFromFileContent", "true");

return attribute;

}



Did this answer your question?