• SOLVED Append Workflow Comments to File Metadata

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
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.
 #41331  by alexwgordon
 
Hi All,

I'm working on a workflow and it has some collaboration aspects to it. The users will use the Comment Section above the Workflow Form to make notes back and forth. I was wondering if it is possible, once the file is approved, can the list of comments be appended to the file somehow? If so that would be great. Thanks in advance!
Attachments
Screen Shot 2016-02-18 at 15.34.10.png
Screen Shot 2016-02-18 at 15.34.10.png (30.39 KiB) Viewed 5297 times
Last edited by alexwgordon on Fri Apr 15, 2016 3:21 pm, edited 2 times in total.
 #41338  by jllort
 
We are talking about PDF files ? ( the mime type of the documents is important, because is not the same, if you want for all mime I suggest forget the idea, for the most commons can be done ). Basically you need to openning the file and attach pages at the end or write lines ( depending the mime type format ).
 #41340  by alexwgordon
 
I am talking about all mime types. But I should clarify that I don't want to add the comments into[\b] the file, I just want to add it to the metadata. Possibly to the history or in the notes of the file. Does that make sense?
 #41348  by jllort
 
Then the comment field should going into the forms.xml defintion and in transaction store as a note or into metadata field.
 #41425  by jllort
 
You can get the field from the transaction view ( see http://docs.openkm.com/kcenter/view/wfg ... ercise.htm ) and about saving value into metadata field take a look at http://docs.openkm.com/apidoc/com/okm/6 ... Group.html ( I suggest the method setPropertiesSimple(String token, String nodeId, String grpName, Map<String,String> properties) )
 #41470  by alexwgordon
 
hi jllort, so after looking at the links you posted, I'm still not sure how to retrieve the Comments themselves. I'm not sure which method to use nor if I should be doing a getVariable. I tried a getVariable("comments") but came back as null. I think if you could help me to understand that much, I could figure the rest out. See the attached image for the comments I'm referring to at the bottom of the picture. Thanks!
Attachments
Screen Shot 2016-03-18 at 13.03.44.png
Screen Shot 2016-03-18 at 13.03.44.png (31.66 KiB) Viewed 5240 times
 #41476  by pavila
 
In short, you have two kinds of comments:

- Comments handled by the workflow engine, which can be accesses from the workflow info (See attached screenshot) which appears in the administration part under the "Comments" section. These comments can be obtained this way:
Code: Select all
processInstance.rootToken.comments
- Comments in forms.xml, which you have to handle and eventually store in database or as document notes. These comments appears as process instance variables.

For the sake of simplicity, we have already remove the first one from OpenKM Professional. And because you don't have any opportunity of intercepting them and use them for any purpose you want.
Attachments
Selección_018.png
Selección_018.png (6.65 KiB) Viewed 5234 times
 #41480  by alexwgordon
 
Thanks jlllort, that's exactly what I was looking for! However, when I try
Code: Select all
ProcessInstance.rootToken.comments
I'm getting an error that rootToken is not visible or if I use the getRootToken() method, it says it's not a static method. I think this may be my inexperience causing my mistake.

Okay, so if the first instance of comments is going to be removed, you're only going to have the comments as process variables in future revisions? What would be the easiest way to show ALL the comments to the user throughout the workflow in that case (especially as more comments come in)?

Thanks!
 #41482  by pavila
 
Yes, because it's not an static method. You have to get the ProcessInstance object instance (For example OKMWorkflow.getInstance().getProcessInstance(token, procInsId)) and then getRootToken().
 #41506  by alexwgordon
 
Hi Pavilia,

Thanks for your input! I'm getting myself very confused. I only know Java informally so some of these things are outside of my knowledge at the moment. I'm trying to utilize the OKMWorkflow.getInstance.getProcessInstance(token, processInstanceId), but I'm running into how to obtain the token and the processInstanceId. Can you help point me in the right direction here? I'm getting overwhelmed with all these different methods and classes right now. Thanks!
 #41535  by alexwgordon
 
Hi jllort and pavilia!

So far I know i need to get
Code: Select all
OKMWorkflow.getInstance().getProcessInstance(token,processInstanceId)
getRootToken()
processInstance.rootToken.comments
But how do I get the token and processInstanceId? Would really appreciate your help! Thanks! :)
 #41561  by pavila
 
The authentication token can be obtained this way:
Code: Select all
DbSessionManager.getInstance().getSystemToken()
The processInstanceId can be obtained from the ExecutionContext.
 #41573  by alexwgordon
 
Okay, thank you guys so much for your help. Got it working now. It's probably coded poorly, but here is my final results:
Code: Select all
package com.openkm.workflow.approval;

import java.util.Calendar;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import com.openkm.api.*;
import com.openkm.bean.workflow.Comment;
import com.openkm.module.db.stuff.DbSessionManager;
import java.lang.String;


public class getNotes implements ActionHandler {
	
	private static final long serialVersionUID = 1L;
	
	public void execute(ExecutionContext context) throws Exception {
		
		String token = DbSessionManager.getInstance().getSystemToken();
		Long processInstanceId = context.getProcessInstance().getId();
		List< Comment > commEX = OKMWorkflow.getInstance().getProcessInstance(token, processInstanceId).getRootToken().getComments();
		String uuid = (String) context.getContextInstance().getVariable("uuid");
		String commentString = "";
		StringBuilder sb = new StringBuilder();
		Formatter formatter = new Formatter(sb, Locale.US);
		
		int i = 0;
		while ( i < commEX.size() )
		{
			String mess = commEX.get(i).getMessage();
			String act = commEX.get(i).getActorId();
			Calendar now = commEX.get(i).getTime();
			int year = now.get(Calendar.YEAR);
			int month = now.get(Calendar.MONTH)+1;
			int day = now.get(Calendar.DAY_OF_MONTH);
			int hour = now.get(Calendar.HOUR_OF_DAY);
			int minute = now.get(Calendar.MINUTE);
			commentString = formatter.format("%d.%02d.%02d %02d:%02d - %s - %s%n", year, month, day, hour, minute, act, mess).toString();
			i++;
		}
		formatter.close();
		OKMPropertyGroup.getInstance().setPropertySimple(token, uuid, "okg:commentHistory", "okp:reviewerCommentArea", commentString);
    }
}
 #45015  by dferguson
 
I am trying to implement something very similar, however when I try to reused alexwgordon's code I get a bunch of broken items.

First it cannot resolve the following imports...
Screenshot from 2017-12-06 15-13-33.png
Screenshot from 2017-12-06 15-13-33.png (13.3 KiB) Viewed 4549 times
Edit: Found solution here...

viewtopic.php?t=7399

However, I am not certain I want to go down this path just to get an "approval" comment attached to a document. Surely there is an easier way to implement a document review and approval process that would be traceable...

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.