Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Rename Files Using Custom Attribute Values Upon Download

Groovy Script - Rename Files Using Custom Attribute Values Upon Download

Updated over 3 weeks ago

Description: Sample Groovy script to rename files with custom attribute values upon download.

Click here to learn more.

Context: Document

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?