Building the "Order Management" Training App : Customizing exports - Publications
Prerequisite : The Supplier, Product, Client and Order objects are linked together
What is a Publication ?
In Simplicité, publications allow you to generate custom exports. Whether using template files, expressions, or Java methods, publications offer flexible ways to produce structured documents and reports... Learn more
Exporting in Excel the list of a Supplier's Products
To add a Publication to TrnSupplier, follow the steps below :
- In the Business objects > Business objects menu, open TrnSupplier
- In the Publications panel, click Create
- Fill in the Publication information like so :
- Code : TrnSupPublication
- Usage : On object only
- Visibility : Visible
- Translation : Test Excel Publication
- Output file name : Export-[VALUE:trnSupName]
- Forced MIME type : Microsoft Excel
- Type : Method
- Method : printExcel
- Click Save & Close
- Open the Code editor by clicking
- Click Confirm
- Add the
printExcel
method to theTrnSupplier
Class :
import org.apache.poi.ss.usermodel.Sheet;
[...]
public byte[] printExcel(PrintTemplate pt) {
//SQL query : List of products linked to the Supplier
String sqlQuery = "select trn_prd_reference, trn_prd_name, trn_prd_stock, trn_prd_price from trn_product where trn_prd_sup_id="+getRowId();
try {
ExcelTool xls = new ExcelTool(true);
Sheet sheet = xls.addSheet("Simple sheet");
int line = 0;
// use Grant.query to retrieve a List<String[]> containing the results from the query defined above
for(String[] row : getGrant().query(sqlQuery)){
ExcelTool.ExcelRow nRow = new ExcelTool.ExcelRow(line++);
int col=0;
for (String cell : row)
nRow.add(new ExcelTool.ExcelCell(col++, cell));
xls.addRow(sheet, nRow);
}
return xls.generateToByteArray();
} catch(Exception e){
AppLog.error(e, getGrant());
return null;
}
}
- Click Save
Test the Pivot table with the usertest User
-
Clear the platform's cache and log in using usertest
For a detailed step-by-step, see : Testing the User
-
Open a Supplier
-
Create Products for the Supplier if it has none
Success
An Excel spreadsheet is downloaded when the Publication button is clicked
