Skip to main content
Groovy Script - Update Document Attributes
Updated yesterday

Description: Sample groovy script to update document attributes (includes both basic and custom attributes)

Context: Document

Remark: Accessible in 'Post' task mode only

Script:

def execute(){

HashMap<Object, Object> optionMap = new HashMap();

optionMap.put(RevisionDetailsOption.BASIC_DETAILS, true);

optionMap.put(RevisionDetailsOption.CUSTOM_ATTRIBUTES, true);

// this is optional and used when user get date as per apply timezone optionMap.put(RevisionDetailsOption.APPLY_TIMEZONE, IGroovyConstant.PUBLISHER);

DocumentVO documentVO = documentService.getDocumentDetails(optionMap);

// Update Basic Attributes

documentVO.setDocRef(documentVO.getDocRef() + "_1");

documentVO.setRevision(documentVO.getRevision() + "_1");

documentVO.setDocTitle(documentVO.getDocTitle() + "_1");

documentVO.setPurposeOfIssue("For Approval"); //Make sure you provide exact name of POI. It is case sensitive.

documentVO.setPrivate(false);

documentVO.setRevisionNotes(documentVO.getRevisionNotes() + "_1");

// Update Custom Attributes. Make sure you provide exact original name of custom attribute, not language specific. It is case sensitive.

Map<String, List<String>> customAttributeMap = new HashMap<String, List<String>>();

// DROPDOWN

List<String> dropDownValue = new ArrayList<String>();

dropDownValue.add("Tower 1"); // make sure you provide proper value here which is exist in this custom attribute

customAttributeMap.put("Site", dropDownValue);

// MULTI CHECKBOX

List<String> multiCheckboxValues = new ArrayList<String>();

multiCheckboxValues.add("Project Management Consultant"); // make sure you provide proper value here which is exist in this custom attribute

multiCheckboxValues.add("External Consultant"); // make sure you provide proper value here which is exist in this custom attribute

customAttributeMap.put("Drawing Reviewed by", multiCheckboxValues);

// DATE PICKER

List<String> datePickerValue = new ArrayList<String>();

datePickerValue.add("25-Jan-2019"); // Date should be in provided format only.

customAttributeMap.put("Project Start Date", datePickerValue);

//RADIO BUTTON

List<String> radioButtonValues = new ArrayList<String>();

radioButtonValues.add("Yes");

customAttributeMap.put("Review Approved?", radioButtonValues);

//TEXT BOX

List<String> textBoxValue = new ArrayList<String>();

textBoxValue.add("Drawing looks perfect!");

customAttributeMap.put("Remarks", textBoxValue);

//COORDINATES

List<String> coordinatesValues = new ArrayList<String>();

coordinatesValues.add("444");

coordinatesValues.add("555");

coordinatesValues.add("666");

customAttributeMap.put("Coordinates", coordinatesValues); // make sure you add values for all the coordinates defined in custom attributes 1/2/3.

//MAP

List<String> mapValue = new ArrayList<String>();

mapValue.add("55.68970825,-1.91009712"); // This should be based on Type of Map

customAttributeMap.put("MAP", mapValue);

documentVO.setCustomAttribute(customAttributeMap);

ArrayList<DocumentVO> documents = new ArrayList<DocumentVO>();

documents.add(documentVO);

// Assign attributes to documents

documentService.updateDocuments(documents);

// this is optional and used when user get date as per apply timezone

HashMap<Object, Object> optionDataMap = new HashMap(); optionDataMap.put(RevisionDetailsOption.APPLY_TIMEZONE, IGroovyConstant.PUBLISHER);

// Assign attributes to documents optionDataMap is optional documentService.updateDocuments(documents,optionDataMap);

}



Did this answer your question?