Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Fetch list of Documents by Custom Attribute and update title of all private Documents from the list
Groovy Script - Fetch list of Documents by Custom Attribute and update title of all private Documents from the list
Updated over a month ago

Description: Sample groovy script to fetch list of documents based on custom attribute's value and update title of all the available private documents from the list

Context: Document

Remark: Accessible in 'Post' task mode only

Script:

def execute(){

String attributeName = "AppStatus";

String attributeValue = "Rejected";

String folderPath = "Asite Project\\Documents";

HashMap optionMap = new HashMap<>();

optionMap.put(RevisionDetailsOption.LATEST_REVISION,true);

//optionMap.put(RevisionDetailsOption.ALL_REVISION,true); // if you want all the revisions, use this option instead of above.

List<DocumentVO> documents = documentService.getDocsByCustomAttribute(attributeName, attributeValue, folderPath, optionMap);

for(DocumentVO doc: documents){

if (doc.isPrivate()){

List<String> customAttributeValueList = documentService.getCustomAttributeValue(doc, "App Title");

String appTitle = customAttributeValueList.get(0);

documentContext.getDocVO().docTitle = appTitle;

documentService.updateDocument(documentContext);

}

}

}



Did this answer your question?