Skip to main content

Groovy Script - Rename Files Using Custom Attribute Values Upon Download

Description: Sample Groovy Script to rename files with Custom Attribute values upon download.

Click here to learn more.

Context: Document

Document Type: File

Remark: Accessible in 'Pre' task mode only

Script:

def execute(){
DocumentVO document = documentService.getDocumentDetails();
String fileName = document.getFileName().substring(0, (document.getFileName().lastIndexOf(".")));
String fileExt = document.getFileName().substring(document.getFileName().lastIndexOf("."));

String docTypeCode = getValue(documentService.getCustomAttributeValue(document,"Document_Type_Code")); // Dropdown

String docCodeSeq = getValue(documentService.getCustomAttributeValue(document,"Document_Code_Seq")); // Textbox

String supportedDocTypes = getValue(documentService.getCustomAttributeValue(document,"Supported_Doc_Types")); // Multi-selection checkbox
document.setFileName(fileName + "-" + docTypeCode + "-" + docCodeSeq + "-" + supportedDocTypes +"-" + document.getVer() + fileExt);

return setResponse(document);
}
// This method will give all the values as comma separated string
private String getValue(List<String> valList)
{
String retValue = valList != null ? String.join(",",valList) : "";
return retValue;
}
//Do not update below script
private DocumentVO setResponse(document){
document.setResponseStatus(false);
return document;
}
Did this answer your question?