Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Make any or all of the document attributes non-editable on 'Upload' and 'Edit Attributes' screen
Groovy Script - Make any or all of the document attributes non-editable on 'Upload' and 'Edit Attributes' screen
Updated yesterday

Description: Sample groovy script to make any or all of the document attributes non-editable on 'Upload' and 'Edit Attributes' screen

Below sample groovy script will make 'Rev' standard attribute and 'PROJECT COST' custom attribute non-editable in 'Upload Document' and 'Edit Attribute' screens. For custom attributes, user needs to pass attribute name itself instead of IDocumentAttribute.REV.

Supported standard attributes of document:

IDocumentAttribute.DOC_REF

IDocumentAttribute.REV

IDocumentAttribute.DOC_TITLE

IDocumentAttribute.POI

IDocumentAttribute.STATUS

IDocumentAttribute.DOC_PRIVACY

IDocumentAttribute.REV_NOTES

IDocumentAttribute.ATTACH_FILE

Context: Document

Remark: Accessible in 'On-Load' task mode only

Script:

def execute(){

JsonArray attributeDetailsList = new JsonArray();

DocumentVO document = documentService.getDocumentDetails();

String revDefaultValue = "-";

attributeDetailsList.add(getAttributeJSON(IDocumentAttribute.REV, IDocumentAttribute.STANDARD, IDocumentAttribute.READ_ONLY, revDefaultValue)); // Params: Attribute Name, Type Of Atribute, Editable/Read Only, default value

String defaultValue = "55555";

attributeDetailsList.add(getAttributeJSON("PROJECT COST", IDocumentAttribute.CUSTOM, IDocumentAttribute.READ_ONLY, defaultValue));

document.setResponseStatus(false);

document.setDynamicObject(attributeDetailsList.toString());

return document;

}

// This is a generic method to prepare JSON object. No need to do any change in this method.

private JsonObject getAttributeJSON(String attributeName, boolean isCustomAttribute, boolean editOption, String defaultValue) {

JsonObject attribute = new JsonObject();

attribute.addProperty("attributeName", attributeName);

attribute.addProperty("isEditable", editOption);

attribute.addProperty("isCustomAttribute", isCustomAttribute);

attribute.addProperty("defaultValue", defaultValue);

return attribute;

}



Did this answer your question?