Create report from datasource

Hello,

I want to create a report.

I can create a record from an entity without problems. But I want to create a report from a datasource, which I use to show the entries in a table in cuba. The logic is made in the backend and sended to cuba via rest.

Have you an idea how can I achieve that?

Thanks
Best regards

Hi,

You can try creating a report with a List of entities dataset, or select List of entities selected by query in the wizard, defining the same query as in your datasource in the backend.

Suppose you have a service that selects some order on a certain condition, for example:

@Service(ReportDataService.NAME)
public class ReportDataServiceBean implements ReportDataService {

    @Inject
    private Persistence persistence;

    @Override
    public List<Order> getTodaysOrders() {
        Query query = persistence.getEntityManager().createQuery(
                "select o from sales$Order o where @between(o.createTs, now, now+1, day)");
        return query.getResultList();
    }
}

The same result can be easily achieved with List of entities selected by query dataset, where the query is the following:

select
e.amount as "amount",
customer.name as "customer.name",
e.date as "date"
from sales$Order e  
left join e.customer customer 
where @between ( e.createTs, now, now + 1, DAY)