• SOLVED Setting users with role as <select> field options

  • 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.
 #40440  by alexwgordon
 
Hi Guys,

So I'm trying to create a dynamic <SELECT> dropdown field in a workflow form. I want it to show the all users with the ROLE of "REVIEWER".

I was looking at the forums and reading documentation in hopes to figure this out on my own. I saw this post http://forum.openkm.com/viewtopic.php?f ... 1&start=15, but was unable to deploy the workflow if I tried:
Code: Select all
<select label="Assign User" name="username" type="simple" table="okm_user_role" className="openkm.select.values.ListClass" />
or
Code: Select all
<select label="Assign User" name="username" type="simple" table="okm_user_role" class="openkm.select.values.ListClass" />
I would receive the errors:
Code: Select all
Deployment Failed: Unexpected exception while receiving the response from the server.
Deployment Failed: The process archive could not be deployed.
As soon as I removed the class or className, the workflow would deploy. I've also tried running a query (I tested in Admin > Query to make sure it was the correct query):
Code: Select all
 <select label="Assign User" name="username" type="simple" table="okm_user_role" optionsQuery="SELECT UR_USER FROM `okm_user_role` as role WHERE UR_ROLE in('REVIEWER')" />
The workflow would deploy, but I would just get a SELECT field with no values.

Does anyone have any help or suggestions? I would greatly appreciate your help in the matter! Thank you so much guys! :)
Last edited by alexwgordon on Fri Sep 04, 2015 4:46 pm, edited 1 time in total.
 #40443  by jllort
 
The class name is wrong, should be "com.openkm.select.values.ListClass"

In source code actually only exists the ListClass.java but you can create your own class for listing roles. This is the code of ListClass.java
Code: Select all
package com.openkm.select.values;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMAuth;
import com.openkm.bean.form.Option;

/**
 * @author lazarovski
 */
public class ListClass implements OptionSelectValues {
	@Override
	public List<Option> getOptions() {
		List<Option> options = new ArrayList<Option>();
		try {
			List<String> userList = OKMAuth.getInstance().getUsers(null);
			for (String user : userList) {
				Option option = new Option();
				option.setLabel(OKMAuth.getInstance().getName(null, user));
				option.setValue(user);
				options.add(option);
			}
			
		} catch (Exception e) {
			System.out.println("Exception occured: " + e.getMessage());
		}
		return options;
	}
}
 #40448  by alexwgordon
 
Ah of course. I should have proofread that code better! Thanks jllort :)

Got this one solved as well now! Simple switch to getUsersByRole(null,"ROLE"). But the class had to be compiled with OpenKM for some reason and wouldn't let me build it as a workflow java file. I'm assuming because it needs to be generate first before the workflow?

Either way problem solved :)
Code: Select all
public class ListRole implements OptionSelectValues {
	@Override
	public List<Option> getOptions() {
		List<Option> options = new ArrayList<Option>();
		try {
			List<String> userList = OKMAuth.getInstance().getUsersByRole(null,"REVIEWER");
			for (String user : userList) {
				Option option = new Option();
				option.setLabel(OKMAuth.getInstance().getName(null, user));
				option.setValue(user);
				options.add(option);
			}
			
		} catch (Exception e) {
			System.out.println("Exception occured: " + e.getMessage());
		}
		return options;
	}
}
 #40453  by jllort
 
The class is called internally by OpenKM, not from workflow side. Workflow call OpenKM api to retrieve metadata forms ( here you are into OpenKM application, that's why you need to deploy the updated OpenKM.war file otherwise application can not reference the class ).

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.