Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Validate Doc Ref Uniqueness at Project Level by excluding linked documents
Groovy Script - Validate Doc Ref Uniqueness at Project Level by excluding linked documents
Updated today

Description: Sample groovy script to validate document reference uniqueness at project level by excluding linked documents.

Context: Document

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: 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();

// Step 4: Check for document existence at the project level , Ensures 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 document exists , 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;

}



Did this answer your question?