SOLVED Append Workflow Comments to File Metadata

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.
alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

SOLVED Append Workflow Comments to File Metadata

Post by alexwgordon » Thu Feb 18, 2016 11:34 pm

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
Last edited by alexwgordon on Fri Apr 15, 2016 3:21 pm, edited 2 times in total.

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

Re: Append Workflow Comments to File Somehow

Post by jllort » Sat Feb 20, 2016 11:05 am

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

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Somehow

Post by alexwgordon » Sat Feb 20, 2016 4:56 pm

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?

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

Re: Append Workflow Comments to File Somehow

Post by jllort » Wed Feb 24, 2016 11:23 am

Then the comment field should going into the forms.xml defintion and in transaction store as a note or into metadata field.

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Somehow

Post by alexwgordon » Thu Mar 03, 2016 6:22 pm

what method can I use to extract the comments and inject them into a metadata field / note?

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

Re: Append Workflow Comments to File Somehow

Post by jllort » Mon Mar 07, 2016 10:58 am

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

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Somehow

Post by alexwgordon » Fri Mar 18, 2016 8:04 pm

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

pavila
Moderator
Moderator
Posts: 3036
Joined: Tue Dec 11, 2007 6:02 pm
Location: Alicante, Spain
Contact:

Re: Append Workflow Comments to File Somehow

Post by pavila » Tue Mar 22, 2016 11:35 am

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 694 times

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Somehow

Post by alexwgordon » Wed Mar 23, 2016 2:05 am

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!

pavila
Moderator
Moderator
Posts: 3036
Joined: Tue Dec 11, 2007 6:02 pm
Location: Alicante, Spain
Contact:

Re: Append Workflow Comments to File Somehow

Post by pavila » Wed Mar 23, 2016 8:19 am

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

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Somehow

Post by alexwgordon » Fri Mar 25, 2016 11:58 pm

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!

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Metadata

Post by alexwgordon » Thu Mar 31, 2016 1:46 pm

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! :)

pavila
Moderator
Moderator
Posts: 3036
Joined: Tue Dec 11, 2007 6:02 pm
Location: Alicante, Spain
Contact:

Re: Append Workflow Comments to File Metadata

Post by pavila » Wed Apr 06, 2016 7:20 am

The authentication token can be obtained this way:

Code: Select all

DbSessionManager.getInstance().getSystemToken()
The processInstanceId can be obtained from the ExecutionContext.

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Append Workflow Comments to File Metadata

Post by alexwgordon » Fri Apr 08, 2016 10:29 pm

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

dferguson
Senior Boarder
Senior Boarder
Posts: 51
Joined: Thu May 18, 2017 12:48 pm

Re: SOLVED Append Workflow Comments to File Metadata

Post by dferguson » Wed Dec 06, 2017 8:15 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests