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 the 'Upload' and 'Edit Attributes' screens
Groovy Script - Make any or all of the document attributes non-editable on the 'Upload' and 'Edit Attributes' screens
Updated this week

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

The following sample Groovy script will make the 'Rev' standard attribute and 'PROJECT COST' custom attribute fields non-editable in the 'Upload Document' and 'Edit Attributes' screens. For custom attributes, the user needs to pass the attribute name itself instead of IDocumentAttribute.REV.

Setting values to attributes is not supported for the On-Load Edit Attribute event; it is only supported in the On-Load Upload event.

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?