How to find current document in Automation

OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules
Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
Post Reply
ChrisDo84
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Thu Jan 09, 2014 11:52 am

How to find current document in Automation

Post by ChrisDo84 » Mon Jan 27, 2014 2:05 pm

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);
					}
				}
			}
		}
	}
}

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: How to find current document in Automation

Post by jllort » Wed Jan 29, 2014 6:18 pm

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

ChrisDo84
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Thu Jan 09, 2014 11:52 am

Re: How to find current document in Automation

Post by ChrisDo84 » Fri Jan 31, 2014 3:25 pm

Hello,

the variable uuid is always undefined.

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: How to find current document in Automation

Post by jllort » Tue Feb 04, 2014 6:34 pm

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

vrecalde_py
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: Fri Aug 31, 2018 7:24 pm

Re: How to find current document in Automation

Post by vrecalde_py » Mon Sep 10, 2018 3:08 pm

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.

vrecalde_py
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: Fri Aug 31, 2018 7:24 pm

Re: How to find current document in Automation

Post by vrecalde_py » Mon Sep 10, 2018 3:45 pm

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?

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: How to find current document in Automation

Post by jllort » Thu Sep 13, 2018 6:19 am

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.

Post Reply