Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Stop upload process if Doc Ref doesn't match with specific pattern & display message to User
Groovy Script - Stop upload process if Doc Ref doesn't match with specific pattern & display message to User
Updated over a month ago

Description: Sample groovy script to stop upload process if document reference doesn't match with specific pattern and display message to user.

Context: Document

Remark: Accessible in 'Pre' task mode only

Script:

[Pattern: Doc Ref should start with one and only one alphabet +

Minimum 2 digit number... it can be more +

A .(dot) +

Should end with minimum 1 digit number... it can be more.

E.g. A0001.555]

def execute(){

DocumentVO document = documentService.getDocumentDetails();

if (!document.getDocRef().matches("^[A-Za-z][0-9]{2,}[.][0-9]{1,}")) {

document.setResponseStatus(false);

document.setResponseMessage("DocRef pattern does not match with expected pattern : A001.555, please update.");

}

return document;

}

[To validate a Doc Ref by applying a numbering rule]

def execute(){

DocumentVO document = documentService.getDocumentDetails();

String separator = "-";

String Project_Code = "A1234";

String Originator = "[A-Za-z]{3}";

String Site_Code = "(0101|0102|0103|0104|0105|0106)";

String Asset_Code = "(001|002|003|004|A12|B23|C24)";

String Discipline = "(ARCH|STR|INT|EXT|CVL|MECH)";

String Doc_Type = "(ABC|DEF|GHI|JKL)";

String Sequence = "[0-9]{4}";

String Doc_Ref_Rule = Project_Code + separator + Originator + separator + Site_Code + separator + Asset_Code + separator + Discipline + separator + Doc_Type + separator + Sequence;

if (!document.getDocRef().matches(Doc_Ref_Rule)) {

document.setResponseStatus(false);

document.setResponseMessage("DocRef pattern does not match with expected pattern : A1234-JOHN-0101-001-ARCH-ABC-0001, please update accordingly.");

}

return document;

}



Did this answer your question?