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 a week ago

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

Click here for detailed help.

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?