Description:
Sample Groovy Script to validate document title uniqueness at the Folder level for Files and Placeholders across all revisions.
If a duplicate title is detected within the folder, the upload or update action is blocked with an appropriate validation message.
Context: Document
Remark: Accessible in Pre task mode only.
Script:
def execute(){
// Step 1: Create a HashMap to store options
HashMap<Object, Object> optionMap = new HashMap();
// Step 2: Set a specific option EXCLUDE_LINKED_DOCS to Excludes linked documents for accurate uniqueness checking.
optionMap.put(RevisionDetailsOption.EXCLUDE_LINKED_DOCS, true);
// Step 3: Retrieve document details
DocumentVO document = documentService.getDocumentDetails();
Set<String> attributes = [IDocumentAttribute.DOC_TITLE] as Set
// Step 4: Check for document existence at the project level , Ensures uniqueness of DocRef within the project.
Set<String> existAttributes = documentService.isAttributeValueExist(document, attributes,
RevisionDetailsOption.FOLDER_LEVEL_INCLUDE_PLACEHOLDER, optionMap);
// Step 5: Set response status and message if document exists , Indicates a conflict for user action.
if (existAttributes.contains(IDocumentAttribute.DOC_TITLE)) {
document.setResponseStatus(false);
document.setResponseMessage(document.getDocTitle() + " : Doc Title already exists, please update.");
}
// Step 6: Return the document after execution
return document;
}