Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Display a colour coded status bar upon QR code scan (for 'Static' QR code type)
Groovy Script - Display a colour coded status bar upon QR code scan (for 'Static' QR code type)
Updated over a month ago

Description: Sample groovy script to display a colour coded status bar upon QR code scan (for 'Static' QR code type)

Context: Document

Remark: Accessible in 'On Load' task mode only

def execute() {

//********************* Configurable parameter section *********************************

String defaultTitle = "DEFAULT"; // This message will be displayed when predefined status not found

String emptyRevNotesMsg = "EMPTY";

//********************* Configurable parameter section *********************************

// Get Current Revision Detail

DocumentVO document = documentService.getDocumentDetails();

// Get Static Data of all revisions and latest data of later revisions.

QRCodeStaticDataVO staticData = documentService.getStaticDataOfQRCode(document);

if (staticData != null && staticData.getStatus() != null) {

JsonObject response = new JsonObject();

// Set statusBar

JsonObject statusBar = getStatusBarDetails(staticData,defaultTitle);

// Set Revision Notes details

String revIdsForRevNotes = getRevIdForRevNotes(staticData);

response.add(IGroovyConstant.STATUS_BAR, statusBar);

response.addProperty(IGroovyConstant.REVISION_IDS_FOR_REV_NOTES, revIdsForRevNotes);

response.addProperty(IGroovyConstant.IS_DISPLAY_GENERATED_DATE, "true");

if (revIdsForRevNotes.isEmpty()) {

response.addProperty(IGroovyConstant.EMPTY_REV_NOTES_MSG, emptyRevNotesMsg);

}

document.setResponseStatus(false);

document.setDynamicObject(response.toString());

}

return document;

}

// This method is used for adding status bar in QR code. we can change this value as per requirements.

public JsonObject getStatusBarDetails(QRCodeStaticDataVO staticData, String defaultTitle) {

//set message as per requirements

String msg = defaultTitle;

String RED = IGroovyConstant.COLOR_RED;

String GREEN = IGroovyConstant.COLOR_GREEN;

String GREY = IGroovyConstant.COLOR_GREY;

String color = RED; // Default exception color

if (staticData.getStatus().equals("Approved")) {

color = GREEN;

msg = "Message";

} else {

msg = "Message";

color = RED;

}

JsonObject statusBar = new JsonObject();

statusBar.addProperty(IGroovyConstant.STATUS_BAR_MSG, msg);

statusBar.addProperty(IGroovyConstant.COLOR, color);

return statusBar;

}

// We need to display revision notes of revisions.

public static String getRevIdForRevNotes(QRCodeStaticDataVO staticData) {

StringBuilder revisions = new StringBuilder();

List<DocumentVO> otherRevisions = staticData.getOtherRevisionsStaticData();

for (DocumentVO otherRev : otherRevisions) {

revisions.append(otherRev.getRevisionId()).append(",");

}

return revisions.toString();

}



Did this answer your question?