How can I read data from an existing data source?

Question

I want to read the FiscalCalendar data source and get the FiscalData for today's date.

I tried using the api.find method but I get an error stating Could not find property 'attribute1' in the class net.pricefx.domain.DMDataSource"def fiscalDate = api.find("DMDS",Filter.equal("uniqueName","FiscalCalendar"),Filter.equal("attribute1","20170714")).

Answer

What you're looking for is api.getDatamartContext().

In the Analytics module, conversions of a certain Date into Fiscal Year, Quarter, Month and Week are done via a Data Source called "cal", found in Analytics. This is intended to be used only in Analytics, even though you can read it from within any logic in any module.

This Data Source is not populated by default, you must upload the conversion into it (using an XLS file).

Data Sources are queried using a Datamart query (you need to add due null checks and more):

ctx.executeQuery(ctx.newQuery(ctx.getDataSource(name)).select(...).where(...))

Found an issue in documentation? Write to us.