Change folder style by metadata value
The example demostrates how to change folder style icons based on metadata values.
Configure sample
Section titled “Configure sample”Create a new Metadata group
Section titled “Create a new Metadata group”<property-group label="Invoice status" name="okg:invoicedata"><select label="Status" name="okp:invoicedata.status" type="simple"> <option label="Open" value="open" /> <option label="Pending to review" value="review" /> <option label="Closed" value="closed" /></select></property-group>Create new Folder styles
Section titled “Create new Folder styles”Create three new folder styles. Each folder style will use only a single icon for all the status.
| Folder style name | Icon | Internal Id |
|---|---|---|
| green | ![]() |
2 |
| orange | ![]() |
3 |
| red | ![]() |
4 |
Create a new Automation task
Section titled “Create a new Automation task”Create an Automation task:
- Set name “Change icon based on metadata”.
- Choose “Set Property Group” event ( set metadata fields event ).
- Choose “post” on at field.
- Check Active.


- Add an Action based on scripting and set the code below.
Scripting code
import com.openkm.api.OKMPropertyGroup;import com.openkm.bean.PropertyGroup;import com.openkm.api.OKMRepository;import com.openkm.bean.form.FormElement;import com.openkm.bean.form.Select;import com.openkm.bean.form.Option;import com.openkm.api.OKMFolder;
//String uuid = "e0ad61e4-2c2d-429e-aa00-27afa674551d";String path = OKMRepository.getInstance().getNodePath(null, uuid);String grpName = "okg:invoicedata";boolean hasGroup = false;for (PropertyGroup pg : OKMPropertyGroup.getInstance().getGroups(null, path)) { if (pg.getName().equals(grpName)) { hasGroup = true; }}if (hasGroup) { for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) { if (formElement instanceof Select) { Select select = (Select) formElement; for (Option option : select.getOptions()) { if (option.isSelected()) { String fldPath = path.substring(0,path.lastIndexOf("/")); String fldUuid = OKMRepository.getInstance().getNodeUuid(null, fldPath); if (option.getValue().equals("open")) { OKMFolder.getInstance().setStyle(null, fldUuid, 2); } else if (option.getValue().equals("review")) { OKMFolder.getInstance().setStyle(null, fldUuid, 3); } if (option.getValue().equals("closed")) { OKMFolder.getInstance().setStyle(null, fldUuid, 4); } } } } }}
Check configuration
Section titled “ Check configuration”- Update the metadata group of a document.

- Change the metadata field value from closed to open.

- Click on
Refresh icon at toolbar. - The folder style icon applyed has been changed.
![]()


