System error while running this JAVA action file GenerateExcelDoc in Microflow.

0
Hello All,   I am using a java action in a microflow to export the data in excel file. The Java action in microflow is breaking and giving " An error occurred, please contact your system administrator".  Any solution with this. I am attaching the Java action Screenshots. Also, I have also used error handling to handle any error but it is not hitting the error handling. I am using studio pro 9.21. // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package xlsreport.actions; import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import com.mendix.core.Core; import com.mendix.core.CoreException; import com.mendix.logging.ILogNode; import com.mendix.systemwideinterfaces.core.IMendixObject; import system.proxies.FileDocument; import xlsreport.proxies.MxCellStyle; import xlsreport.proxies.MxColumn; import xlsreport.proxies.MxData; import xlsreport.proxies.MxSheet; import xlsreport.report.DataOQL; import xlsreport.report.data.ColumnPreset; import xlsreport.report.export.Export; import xlsreport.report.export.ExportCSV; import xlsreport.report.export.ExportExcel; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; public class GenerateExcelDoc extends CustomJavaAction<IMendixObject> { private IMendixObject __TemplateObject; private xlsreport.proxies.MxTemplate TemplateObject; private IMendixObject __OutputDocument; private system.proxies.FileDocument OutputDocument; private IMendixObject InputObject; public GenerateExcelDoc(IContext context, IMendixObject TemplateObject, IMendixObject OutputDocument, IMendixObject InputObject) { super(context); this.__TemplateObject = TemplateObject; this.__OutputDocument = OutputDocument; this.InputObject = InputObject; } @java.lang.Override public IMendixObject executeAction() throws Exception { this.TemplateObject = this.__TemplateObject == null ? null : xlsreport.proxies.MxTemplate.initialize(getContext(), __TemplateObject); this.OutputDocument = this.__OutputDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __OutputDocument); // BEGIN USER CODE // Check first if the input is correct as configured if (TemplateObject.getMxTemplate_InputObject() != null && InputObject != null) { String expectObject = TemplateObject.getMxTemplate_InputObject().getCompleteName(); if (!Core.isSubClassOf(expectObject, InputObject.getType())) { throw new CoreException("Cannot create excel, because the inputobject isn't a subclass of configured. Expect: "+expectObject+" Retrieved: " +InputObject.getType()); } } else if(TemplateObject.getMxTemplate_InputObject() != null) { String expectObject = TemplateObject.getMxTemplate_InputObject().getCompleteName(); throw new CoreException("Cannot create excel, because the inputobject isn't given. Expect: "+expectObject); } // Start te export try (Export export = createExport()) { String filename = createFilename(); // Get all the sheets List<IMendixObject> Sheets = Core.retrieveXPathQuery(this.getContext(), "//" + MxSheet.getType() + "[" + MxSheet.MemberNames.MxSheet_Template.toString() + "='" + this.TemplateObject.getMendixObject().getId().toLong() + "']", Integer.MAX_VALUE, 0, getSortMap(MxSheet.MemberNames.Sequence.toString(), "ASC")); // fill every sheet to the document for (IMendixObject ISheet : Sheets) { MxSheet mxSheet = MxSheet.initialize(this.getContext(), ISheet); // Retrieve the columns of the sheet List<IMendixObject> columns = Core.retrieveXPathQuery(this.getContext(), "//" + MxColumn.getType() + "[" + MxData.MemberNames.MxData_MxSheet.toString() + "='" + mxSheet.getMendixObject().getId().toLong() + "']", Integer.MAX_VALUE, 0, getSortMap(MxColumn.MemberNames.ColumnNumber.toString(), "ASC")); List<ColumnPreset> mxColumnList = new LinkedList<ColumnPreset>(); switch (this.TemplateObject.getDocumentType()) { case CSV: for (IMendixObject obj : columns) { MxColumn mxColumn = MxColumn.initialize(this.getContext(), obj); if (checkValidColumn(mxColumn)) { ColumnPreset preset = new ColumnPreset(mxColumn.getName(), mxColumn.getColumnNumber(), mxColumn.getMxXPath_MxData()); if (mxColumn.getDataAggregate()) { preset.addDataAggregation(mxColumn.getDataAggregateFunction()); } mxColumnList.add(preset); } } break; case XLS: case XLSX: long defaultStyle = mxSheet.getMxSheet_DefaultStyle().getMendixObject().getId().toLong(); for (IMendixObject obj : columns) { MxColumn mxColumn = MxColumn.initialize(this.getContext(), obj); if (checkValidColumn(mxColumn)) { long styleGuid = 0; MxCellStyle style = mxColumn.getMxData_MxCellStyle(); if (style != null) { styleGuid = style.getMendixObject().getId().toLong(); } else { styleGuid = defaultStyle; } ColumnPreset preset = new ColumnPreset(mxColumn.getName(), mxColumn.getNameAsHeader(), mxColumn.getColumnNumber(), mxColumn.getMxXPath_MxData(), styleGuid); if (mxColumn.getResultAggregate()) { preset.addResultAggregation(mxColumn.getResultAggregateFunction()); } if (mxColumn.getDataAggregate()) { preset.addDataAggregation(mxColumn.getDataAggregateFunction()); } mxColumnList.add(preset); } } break; } if (mxColumnList.size() > 0) { // Retrieve the needed data. DataOQL data = new DataOQL(this.getContext(), TemplateObject); // Fill the document with the data. export.buildExportFile(mxSheet, mxColumnList, data.getRowData(mxSheet, this.InputObject, mxColumnList)); } else { throw new CoreException("The document can't be created, because there aren't any columns to export. Please check the logfile."); } } // Create a document to write down the generated excel of CSV if (OutputDocument == null) { OutputDocument = new FileDocument(getContext()); } this.OutputDocument.setName(filename); export.writeData(OutputDocument); } return OutputDocument.getMendixObject(); // END USER CODE } /** * Returns a string representation of this action * @return a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "GenerateExcelDoc"; } // BEGIN EXTRA CODE private static ILogNode log = Core.getLogger("XLSreport"); private boolean checkValidColumn(MxColumn mxColumn) throws CoreException { if (mxColumn.getMxXPath_MxData() == null) { log.warn("Can't add column: " + mxColumn.getColumnNumber() + " - " + mxColumn.getName() + " for sheet: " + mxColumn.getMxData_MxSheet().getName() + ", because the Xpath is missing."); return false; } return true; } public static Map<String, String> getSortMap(String name, String direction) { Map<String, String> sortList = new HashMap<String, String>(); if (name != null && direction != null) { sortList.put(name, direction); } return sortList; } private Export createExport()throws CoreException, IOException { switch(this.TemplateObject.getDocumentType()) { case XLS: case XLSX: log.trace("Use Excel export"); return new ExportExcel(this.getContext(), this.TemplateObject, this.InputObject); case CSV: default: log.trace("Use CSV export"); return new ExportCSV(this.getContext(), this.TemplateObject, this.InputObject); } } private String createFilename() { switch(this.TemplateObject.getDocumentType()) { case XLS: return this.TemplateObject.getName().replace(" ", "_") + ".xls"; case XLSX: return this.TemplateObject.getName().replace(" ", "_") + ".xlsx"; case CSV: default: return this.TemplateObject.getName().replace(" ", "_") + ".csv"; } } // END EXTRA CODE }  
asked
2 answers
1

It looks like you are missing the correct java libraries as it says no method found. You can try updating the module where this java action came from (probably excel exporter)

answered
0

You may also try a different way of exporting via updating the data widgets module and using the javascript action to export to excel from a data grid 2 widget.

 

Mendix Marketplace - Data Widgets

 

Data Grid 2 | Mendix Documentation

answered