Page 1 of 1

How to find current document in Automation

PostPosted:Mon Jan 27, 2014 2:05 pm
by ChrisDo84
I've found the following code in the wiki.
It should change the foldericon based on a value in a certain property group.
I'm using OpenKM Community 6.2.5 an can't find out how to get the uuid of the current folder.

The List in http://wiki.openkm.com/index.php/Automa ... ents_table isn't very helpful.
How can i get the desired uuid?
Code: Select all
import com.openkm.automation.AutomationUtils;
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;
import com.openkm.dao.bean.NodeFolder;
import com.openkm.dao.bean.NodeBase;
    
System.out.println("START");
System.out.println("NODE " + AutomationUtils.getInstance().NODE_PATH);

//String uuid = "86d9ea29-1855-4096-b23b-90846db6b835";
String path = OKMRepository.getInstance().getNodePath(null, uuid);
print(path);
System.out.println("Path " + path);
String grpName = "okg:contract";
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("valid")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 19);
					} else if (option.getValue().equals("cancelled")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 20);
                    } else if (option.getValue().equals("draft")) {
                        OKMFolder.getInstance().setStyle(null, fldUuid, 20);
					} if (option.getValue().equals("expired")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 18);
					}
				}
			}
		}
	}
}

Re: How to find current document in Automation

PostPosted:Wed Jan 29, 2014 6:18 pm
by jllort
Two things:
1- Change folder icon feature is only present in professional 6.4.X what still has not been oficially released ( only partners and few customers have it ).
2- About how get current document. When script is executed injects a var called uuid what contains the document uuid. You can directly use this var from scripting and use to getProperties, Path etc...

Re: How to find current document in Automation

PostPosted:Fri Jan 31, 2014 3:25 pm
by ChrisDo84
Hello,

the variable uuid is always undefined.

Re: How to find current document in Automation

PostPosted:Tue Feb 04, 2014 6:34 pm
by jllort
I take a look at source code of 6.2.5 and all is correct, in scripting is injecting always uuid var:
http://sourceforge.net/p/openkm/code/HE ... pting.java

Re: How to find current document in Automation

PostPosted:Mon Sep 10, 2018 3:08 pm
by vrecalde_py
This is good information, but what if I need to get the uuid from a java class (ActionHandler)? When I submit a workflow and I need the uuid, how can I get it? The docs says that we can use methods like :
String path = OKMRepository.getInstance().getNodePath(null, "064ff51a-b815-4f48-a096-b4946876784f"); but in this method I already have the uuid, this is hard coded, and in the follow code:
String uuid = OKMRepository.getInstance().getNodeUuid(null, "/okm:root/tmp"); I already have the path, this is hard coded, but what if I need the uuid of a directory that I'am creating right now?

Regards.

Re: How to find current document in Automation

PostPosted:Mon Sep 10, 2018 3:45 pm
by vrecalde_py
Is this a valid question here or have I open another thread? I put it here because its about geting uuid. Getting uuid works fine from scripting, but if I making submit from workflow form, how can I get the directory's uuid to set metadata in it?

Re: How to find current document in Automation

PostPosted:Thu Sep 13, 2018 6:19 am
by jllort
You have the uuid of the node on what you are executing the workflow in the context variables of the workflow. I suggest check all the variables you have into.