Folder Style assigned by metadata

From OpenKM Documentation
Jump to: navigation, search

Contents

The script assign folder style to folder based in database metadata values present into document contents into.

Description:

  • Property group ( metadata )
  • Folder Style icon ( Red / Green / Yellow with id values 18, 19, 20)
  • Automation based on property group change


Property 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>


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, 19);
					} else if (option.getValue().equals("review")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 20);
					} if (option.getValue().equals("closed")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 18);
					}
				}
			}
		}
	}
}

Example

Register database metadata values:

Okm user guide 498.png

Register automation task

Okm user guide 499.png


Okm user guide 500.png


Okm user guide 501.png


Change property group values:

Okm user guide 502.png


Change closed property group value to open.


Okm user guide 503.png


Click Refresh.gif refresh icon at toolbar.


Okm user guide 504.png