Hello,
I am using a workflow that works correctly when started manually in the user interface.
This workflow only notifies the respective user and adds a property group to the respective document in which a certain value is set when the workflow is successfully completed.
This workflow should now be executed automatically when the document is created as soon as the document is uploaded to a certain folder using HotFolder.
For this i found these script in the forum:
Now my mistake is either in the assignment of the UUID in the automatic rule or in the use of the UUID in my workflow.
I think the easiest way would be to use the UUID of the document in the automatic rule to start the workflow. But how do I get the UUID of the document in the script?
Here is the fired action from my workflow:
I am using a workflow that works correctly when started manually in the user interface.
This workflow only notifies the respective user and adds a property group to the respective document in which a certain value is set when the workflow is successfully completed.
This workflow should now be executed automatically when the document is created as soon as the document is uploaded to a certain folder using HotFolder.
For this i found these script in the forum:
Code: Select all
The UUID given is a folder UUID. However, if I use a UUID of a folder, my subsequent workflow uses that UUID to add the PropertyGrpup to that UUID (folder). However, the ProperteryGroup should be added to the document and not the folder.import java.util.List;
import java.util.ArrayList;
import com.openkm.api.OKMWorkflow;
List formElements = new ArrayList();
String UUID = "bd62b51c-3102-48c7-bf99-7439b53d4c9a";
int id = 20622;
OKMWorkflow.getInstance().runProcessDefinition(null, new Double(id).longValue(), UUID, formElements);
Now my mistake is either in the assignment of the UUID in the automatic rule or in the use of the UUID in my workflow.
I think the easiest way would be to use the UUID of the document in the automatic rule to start the workflow. But how do I get the UUID of the document in the script?
Here is the fired action from my workflow:
Code: Select all
package com.openkm.workflow.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import com.openkm.api.OKMRepository;
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 java.util.Calendar;
import java.util.List;
import java.text.SimpleDateFormat;
public class Rechnungbuchen_addgroup implements ActionHandler {
private static final long serialVersionUID = 1L;
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
/**
This class update meta data of the document involved in work flow, this sets
1) Document Status
2) Date time
3) User comment (the latest comment of the work flow user)
*/
@Override
public void execute(ExecutionContext executionContext) throws Exception {
String uuid = null;
String path = null;
try {
uuid = (String) executionContext.getContextInstance().getVariable("uuid");
path = OKMRepository.getInstance().getNodePath(null, uuid);
} catch (Exception e) {
e.printStackTrace();
System.out.println("User do have access to this document ... error");
}
String nodeName = executionContext.getNode().getName();
Input usrInput;
String DocStatus = "Initial";
//
// Hard coding the Document meta group name
//
String grpName = "okg:rechnungsdaten";
//
// Get the work flow user short comment and set the document status variable
//
if (nodeName.equals("submitted")) {
DocStatus = "Submitted";
usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
} else if (nodeName.equals("verified")) {
DocStatus = "Verified";
usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
} else if (nodeName.equals("resubmitted")) {
DocStatus = "Pending";
usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
} else if (nodeName.equals("sendback")) {
DocStatus = "Pending";
usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
} else if (nodeName.equals("approved")) {
DocStatus = "Approved";
usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
} else {
DocStatus = "Pending";
usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
}
// Submitted
// Verified
// Approved
// Pending
//
// Get current system date time
//
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
String currentDateTime = (String) sdf.format(cal.getTime());
String comment = "Submitted by dflt";
if (usrInput != null) {
comment = (String) usrInput.getValue();
}
System.out.println("uuid: " + uuid);
System.out.println("Path: " + path);
System.out.println("User Comment: " + comment);
System.out.println("Current DateTime: " + currentDateTime);
System.out.println("Flow at node: " + nodeName);
//
// Use Token only for communication from outside; for in line work flow
// just represent it as ¨null¨
//
// String systemToken = DbSessionManager.getInstance().getSystemToken();
//
try {
System.out.println("Before checking OKMProGrp existince for using addgroup");
if (OKMPropertyGroup.getInstance().hasGroup(null, path, grpName)) {
// Do nothing
} else {
System.out.println("Not having group!!! adding group: " + grpName);
//
// Adds an empty meta data group okg:sysinternal to a node
//
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
}
OKMPropertyGroup.getInstance();
OKMPropertyGroup.setPropertySimple(null, path, grpName, "okp:rechnungsdaten.gebucht", "true");
String lv_col1 = "okp:sysinternal.docstatus";
String lv_col2 = "okp:sysinternal.actiondate";
String lv_col3 = "okp:sysinternal.comment";
/*
* For debug purpose
*
* System.out.println("Before OKMProGrp settings");
* System.out.println("===========================");
* System.out.println("Path: "+ path);
* System.out.println("Group Name: "+ grpName);
* System.out.println(" Col-1>: "+ lv_col1);
* System.out.println(" Col-2>: "+ lv_col2);
* System.out.println(" Col-3>: "+ lv_col3);
* System.out.println("===========================");
*/
if (OKMPropertyGroup.getInstance().hasGroup(null, path, grpName)) {
System.out.println("Group << " + grpName + " >> found..");
// create an instance
OKMPropertyGroup.getInstance();
// print existing for debug purpose
/*
* List<FormElement> fElements3 =
* OKMPropertyGroup.getInstance().getProperties(null,
* path,grpName); for (FormElement fElement3 : fElements3) {
* System.out.print("Label: "+fElement3.getLabel());
* System.out.println(" Value: "+fElement3.getName());
* System.out.println("===========================");
* System.out.println(" String: "+fElement3.toString());
* System.out.println("==========================="); if
* (fElement3.getName().equals(lv_col1)) { Select name =
* (Select) fElement3; List<Option> dElements =
* name.getOptions(); for (Option dElement : dElements) {
* System.out.println("Element Label: "+dElement.getLabel());
* System.out.println("Element Value: "+dElement.getValue());
* System.out.println("Element Select: "+dElement.isSelected());
* } } }
*/
// Set values
List<FormElement> fElements = OKMPropertyGroup.getInstance().getProperties(null, path, grpName);
for (FormElement fElement : fElements) {
if (fElement.getName().equals(lv_col1)) {
//
// Since "okp:sysinternal.docstatus" is of type Select, you have use (Select) class to set the values
//
Select name = (Select) fElement;
List<Option> dElements = name.getOptions();
for (Option dElement : dElements) {
if (dElement.getLabel().equals(DocStatus)) {
dElement.setValue(DocStatus);
dElement.setSelected(true);
} else {
dElement.setSelected(false);
}
}
name.setValue(DocStatus);
name.setOptions(dElements);
} else if (fElement.getName().equals(lv_col2)) {
Input name = (Input) fElement;
name.setValue(currentDateTime);
} else if (fElement.getName().equals(lv_col3)) {
Input name = (Input) fElement;
if (comment.length() < 100) {
name.setValue(comment.substring(0, comment.length()));
} else if (comment != null) {
name.setValue(comment.substring(0, 100));
}
}
}
//
// Set Properties element
//
OKMPropertyGroup.getInstance().setProperties(null, path, grpName, fElements);
//
// Confirm - for debug purpose
//
/*
* List<FormElement> fElements2 =
* OKMPropertyGroup.getInstance().getProperties(null,
* path,grpName); for (FormElement fElement2 : fElements2) {
* System.out.print("Label: "+fElement2.getLabel());
* System.out.println(" Value: "+fElement2.getName());
* System.out.println("===========================");
* System.out.println(" String: "+fElement2.toString());
* System.out.println("==========================="); }
*/
} else {
System.out.println("Specified << " + grpName + " >> group not found");
}
System.out.println("After OKMProGrp setProperties");
} catch (Exception e) {
e.printStackTrace();
}
// Got to next Node
executionContext.getToken().signal();
}
}