• Create report using "Folder path" as report parameter.

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
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.
 #53507  by nishant8900
 
I tried report generation based on open km, used folder path as a parameter it seems to be not working. When i tried to generate a report, the parameter shows empty in value field. Please guide me for further flow.

this is how i have implemented it, using "FolderDocuments.rep"
Code: Select all
<report-parameters>
  <input label="Path" name="path" type="folder"/>
</report-parameters>
 #53541  by nishant8900
 
FolderDocuments.jrxml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Datastore Documents" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenResourceMissingType="Key" uuid="162c8295-0cf8-4b5c-8eb0-5352869b60b2">
	<property name="ireport.scriptlethandling" value="0"/>
	<property name="ireport.encoding" value="UTF-8"/>
	<property name="ireport.zoom" value="1.5"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<import value="net.sf.jasperreports.engine.*"/>
	<import value="java.util.*"/>
	<import value="net.sf.jasperreports.engine.data.*"/>
	<parameter name="host" class="java.lang.String"/>
	<parameter name="path" class="java.lang.String"/>
	<queryString>
		<![CDATA[import javax.jcr.*;
import javax.jcr.util.*;
import org.apache.jackrabbit.*;
import org.apache.jackrabbit.api.*;
import com.openkm.bean.*;
import com.openkm.module.direct.*;

nodeIterator(Node node) {
try {
    //your code here
	 if (node.isNodeType(Document.TYPE)) {
    Node content = node.getNode(Document.CONTENT);
    javax.jcr.Property prop = content.getProperty(JcrConstants.JCR_DATA);
    Value val = prop.getValue();

    if (val instanceof JackrabbitValue) {
      JackrabbitValue j = (JackrabbitValue) val;
      Map ld = new HashMap();
      ld.put("id", j.getContentIdentity());
      ld.put("path", node.getPath());
      al.add(ld);
    }
  } else if (node.isNodeType(Folder.TYPE)) {
    for (Iterator it = node.getNodes(); it.hasNext(); ) {
      nodeIterator((Node)it.next());
    }
  }
}
catch (Throwable ex) {
    log.error("Error in Beanshell", ex);
    throw ex;
}
}
List al = new ArrayList ();
Session jcrSession = DirectRepositoryModule.getSystemSession();
System.out.println("Parameter 'path': " + path);
Node root = jcrSession.getRootNode().getNode(path.substring(1));
nodeIterator(root);

return al;]]>
	</queryString>
	<field name="id" class="java.lang.String">
		<fieldDescription><![CDATA[id]]></fieldDescription>
	</field>
	<field name="path" class="java.lang.String">
		<fieldDescription><![CDATA[path]]></fieldDescription>
	</field>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="44" splitType="Stretch">
			<image>
				<reportElement key="image-1" x="631" y="0" width="150" height="35" uuid="c4b4966d-b62f-450e-9352-69d7e0b82fa8"/>
				<imageExpression></imageExpression>
			</image>
			<textField pattern="yyyy/MM/dd" isBlankWhenNull="false">
				<reportElement key="textField-13" x="0" y="0" width="65" height="10" forecolor="#010101" uuid="a70d4053-6b25-4faa-befb-293a30181ee3"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font fontName="Arial" size="8" isBold="true" isUnderline="false"/>
				</textElement>
				<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
			</textField>
			<textField pattern="h.mm.ss a" isBlankWhenNull="false">
				<reportElement key="textField-14" x="0" y="10" width="65" height="10" forecolor="#010101" uuid="e6eb8e51-1a43-44f7-b277-981945b08915"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font fontName="Arial" size="8" isBold="true" isUnderline="false"/>
				</textElement>
				<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
			</textField>
			<line>
				<reportElement key="line-3" x="-15" y="42" width="796" height="1" forecolor="#010101" uuid="5f534f5e-fdbb-4b1e-bc65-dd759aabca10"/>
				<graphicElement fill="Solid"/>
			</line>
			<staticText>
				<reportElement x="225" y="0" width="297" height="44" uuid="323f9bdb-282b-4004-b2be-bbb570ffde74"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font fontName="SansSerif" size="22" isBold="true" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Folder Documents]]></text>
			</staticText>
		</band>
	</title>
	<pageHeader>
		<band splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="30" splitType="Stretch">
			<line>
				<reportElement key="line-4" x="0" y="28" width="235" height="1" forecolor="#010101" uuid="39f5d127-6f05-42f2-a7c5-8592bf9b1490"/>
			</line>
			<line>
				<reportElement key="line-5" x="245" y="29" width="536" height="1" forecolor="#010101" uuid="fcc44e10-f7f5-47b8-845a-5d6b19acb8dd"/>
			</line>
			<staticText>
				<reportElement x="1" y="14" width="234" height="14" uuid="2424ddbc-2b9d-4af7-82af-2d3052a9bd29"/>
				<textElement>
					<font fontName="SansSerif" isBold="true" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Id]]></text>
			</staticText>
			<staticText>
				<reportElement x="245" y="13" width="65" height="14" uuid="f857c059-7e2e-4e49-bd36-a1826db9824a"/>
				<textElement>
					<font fontName="SansSerif" isBold="true" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Document Path]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="18" splitType="Stretch">
			<textField isBlankWhenNull="false">
				<reportElement key="textField" x="245" y="0" width="536" height="18" uuid="43693903-9542-4122-93d2-4dd7f7ddc4fe"/>
				<textElement>
					<font fontName="Arial"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{path}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="false">
				<reportElement key="textField" x="0" y="0" width="235" height="18" uuid="a039d296-7adf-4c00-9af1-3470e91b93ab"/>
				<textElement>
					<font fontName="Arial"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="30" splitType="Stretch">
			<line>
				<reportElement key="line-2" x="-15" y="4" width="796" height="1" forecolor="#010101" backcolor="#FFFFFF" uuid="3bc47a98-edd3-4fc2-9bb3-bc31557cf496"/>
				<graphicElement fill="Solid"/>
			</line>
		</band>
	</pageFooter>
	<summary>
		<band splitType="Stretch"/>
	</summary>
</jasperReport>
params.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE report-parameters PUBLIC "-//OpenKM//DTD Report Parameters 2.0//EN"
                                   "http://www.openkm.com/dtd/report-parameters-2.0.dtd">
<report-parameters>
  <input label="Path" name="path" type="folder"/>

</report-parameters>
Hi ,

Thanks for replying me. Acutally i am new to openkm, so its difficult to understand. I need a report that has "folder path" as paramter, i need to choose the file / paste the url , then report is generated with that url in path field.

Thanks
 #53561  by jllort
 
* First, in the path variable will arrive the uuid of a node.
* The script is quite strange, you should not use the package org.apache.jackrabbit.* for nothing, should use the getChildren method https://docs.openkm.com/kcenter/view/ok ... etChildren
* What OpenKM version did you have installed?
* I suggest checking your script first in the scripting view.
Code: Select all
import javax.jcr.util.*;
import org.apache.jackrabbit.*;
import org.apache.jackrabbit.api.*;
import com.openkm.bean.*;
import com.openkm.module.direct.*;

nodeIterator(Node node) {
try {
    //your code here
	 if (node.isNodeType(Document.TYPE)) {
    Node content = node.getNode(Document.CONTENT);
    javax.jcr.Property prop = content.getProperty(JcrConstants.JCR_DATA);
    Value val = prop.getValue();

    if (val instanceof JackrabbitValue) {
      JackrabbitValue j = (JackrabbitValue) val;
      Map ld = new HashMap();
      ld.put("id", j.getContentIdentity());
      ld.put("path", node.getPath());
      al.add(ld);
    }
  } else if (node.isNodeType(Folder.TYPE)) {
    for (Iterator it = node.getNodes(); it.hasNext(); ) {
      nodeIterator((Node)it.next());
    }
  }
}
catch (Throwable ex) {
    log.error("Error in Beanshell", ex);
    throw ex;
}
}
List al = new ArrayList ();
Session jcrSession = DirectRepositoryModule.getSystemSession();
System.out.println("Parameter 'path': " + path);
Node root = jcrSession.getRootNode().getNode(path.substring(1));
nodeIterator(root);

return al;]
 #53612  by jllort
 
You are doing strange things in the scripting code like
Code: Select all
Session jcrSession = DirectRepositoryModule.getSystemSession();
In the sample we shared in the documentation should be used:
Code: Select all
String systemToken = DbSessionManager.getInstance().getSystemToken();
Forget to use any class under this package import org.apache.jackrabbit.*;


I suggest:
1- Based in the shared report scheleton you shared, set a break point at https://github.com/openkm/document-mana ... t.java#L45 ( pay special attention in the parameters, is what will coming in your report )

2- Create a script and execute it from Administration > Scripting tools -> first must got the scripting running outside the report and when you success simply change the scripting to use the injected variables from report. If you set a form element named "path" a variable named "path" will be injected by the report and you will be able to use it from your scripting ( for example from the reports pack https://docs.openkm.com/kcenter/view/ok ... -pack.html take a look at logins reports about how variables are shared between the form elements into scripting -> I suggest debug it )

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.