Troubles renaming document whit autoincrement id and metadata
PostPosted:Thu Mar 16, 2017 4:57 am
Hi, I am user of OPEN KM Community Version 6.3.3 build: 8289.
I have troubles renaming the document, I am using this automate rules and script, based on your excellent wiki information, and It's actually working adding metadata whit form the wizard, and id autoincrement, but the rename action is not working .
property group registration:
Screenshot:
Automation information:
document creation and set property group
Document creation, validation and actions
ExecuteScripting info:
Set property group, validation and actions
ExecuteScripting info:
Then, here is the example working, auto increment Id, and setting metadata whit wizard form. but the rename script is not working, thank you for your help.
I have troubles renaming the document, I am using this automate rules and script, based on your excellent wiki information, and It's actually working adding metadata whit form the wizard, and id autoincrement, but the rename action is not working .
property group registration:
Code: Select all
</property-group>
<property-group label="Datos" name="okg:data">
<input label="Id" type="text" name="okp:data.id" width="200px" readonly="true"/>
<input label="Oficio No" type="text" name="okp:data.project.code" width="200px">
<validator type="req"/>
<validator type="maxlen" parameter="10"/>
<validator type="minlen" parameter="3"/>
</input>
<input label="Asunto" type="text" name="okp:data.description" width="200px">
<validator type="req"/>
<validator type="maxlen" parameter="150"/>
</input>
</property-group>
Screenshot:
Automation information:
document creation and set property group
Document creation, validation and actions
ExecuteScripting info:
Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
String grpName = "okg:data";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
// Add Group
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
String id = String.valueOf(DatabaseMetadataDAO.getNextSequenceValue(table, sequenceName));
switch (id.length()) {
case 1:
id = "00000" + id;
break;
case 2:
id = "0000" + id;
break;
case 3:
id = "000" + id;
break;
case 4:
id = "00" + id;
break;
case 5:
id = "0" + id;
break;
}
Map map = new HashMap();
map.put("okp:data.id",id);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
}
Set property group, validation and actions
ExecuteScripting info:
Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Select;
import com.openkm.bean.form.Option;
import com.openkm.util.PathUtils;
import com.openkm.util.FileUtils;
import com.openkm.api.OKMDocument;
String grpName = "okg:data";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
// Evaluate if already has property group
boolean add = true;
String prjCode = "";
String id = "";
String desc = "";
for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) {
if (formElement.getName().equals("okp:data.id")) {
docId = ((Input) formElement).getValue();
add = id.equals("");
} else if (formElement.getName().equals("okp:data.project.code")) {
prjCode = ((Input) formElement).getValue();
} else if (formElement.getName().equals("okp:data.description")) {
desc = ((Input) formElement).getValue();
}
}
// Setting properties
if (add) {
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
}
// rename document
String newName = id + "-" + prjCode + "-" + desc + "." + FileUtils.getFileExtension(PathUtils.getName(path));
OKMDocument.getInstance().rename(null, path, newName);
Then, here is the example working, auto increment Id, and setting metadata whit wizard form. but the rename script is not working, thank you for your help.