Description: Sample Groovy Script to validate document reference uniqueness at the Project level by excluding linked documents.
Context: Document
Document Type: File
Remark: Accessible in 'Pre' task mode only.
Script:
/**
* This script checks the validity of DocRef uniqueness at the project level
* by excluding linked documents.
*/
def execute(){
// Step 1: Create a HashMap to store options
HashMap<Object, Object> optionMap = new HashMap();
// Step 2: Specify the option EXCLUDE_LINKED_DOCS to exclude linked documents for accurate uniqueness checking.
optionMap.put(RevisionDetailsOption.EXCLUDE_LINKED_DOCS, true);
// Step 3: Retrieve document details
DocumentVO document = documentService.getDocumentDetails();
// Step 4: Check for document existence at the project level. It ensures the uniqueness of DocRef within the project.
boolean isExist = documentService.isDocRefExist(document.getDocRef(), RevisionDetailsOption.PROJECT_LEVEL_UNIQUE, optionMap);
// Step 5: Set response status and message if the document exists. It indicates a conflict for user action.
if(isExist){
document.setResponseStatus(false);
document.setResponseMessage(document.getDocRef() + " : DocRef already exists in other folder, please update.");
}
// Step 6: Return the document after execution
return document;
}
