Change folder style by metadata value

The example demostrates how to change folder style icons based on metadata values.

When a document into a folder changes their status value it cause the change of the parent folder icon.

Configure sample

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" />

More information about Metadata.

Create new Folder styles

Create three new folder styles. Each folder style will use only a single icon for all the status.

Folder style nameIconInternal Id






More information about Folder style.

Each folder style internaly have and unique Id. That Id is unique an automatically assigned by application on creation stage. On the sample has been used 2,3,4 unique Id but on your application can be others.

To know what are your Id put your cursor over the Edit folder style icon and copy the url. You'll see something like it:

http://localhost:8080/OpenKM/admin/FolderStyle?action=edit&fs_id=2 where the value of fs_id parameter is the value of the Id you're looking for.

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.

More information about Automation.

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

  • 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.