Description: Sample Groovy Script to make any or all document Attributes non-editable on the Upload and Edit Attributes screens.
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 the Document:
IDocumentAttribute.DOC_REF
IDocumentAttribute.REV
IDocumentAttribute.DOC_TITLE
IDocumentAttribute.POI
IDocumentAttribute.STATUS
IDocumentAttribute.DOC_PRIVACY
IDocumentAttribute.REV_NOTES
IDocumentAttribute.ATTACH_FILE
Context: Document
Document Type: File
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;
}