invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

Filtering on fields from the Twinfield API

Replies happen on the forum.

Go to source

Question

This topic provides information on how to use Invantive SQL to limit the amount of data retrieved from the Twinfield (SOAP) API.

Twinfield administrations sometimes contain a lot of financial data. Via the Twinfield API, enormous amounts of data in 1x can be requested, which also come back in 1x. Outliers of more than a gigabyte of data (uncompressed) in 1 response to a request are not unusual.

Three Twinfield API groups: ProcessXML, Finder and BudgetService.svc

Invantive's Twinfield SQL driver accesses the Twinfield API server via three channels:

  • The financial data is "transaction data" and is offered via the processxml service URL.
  • The tables with relatively little data are offered via the finder service URL.
  • Budget information is available via the BudgetService.svc service URL.

Filtering is not possible for the tables based on the finder service URL and the budget information. That does not need to be a problem, since it concerns relatively small amounts of data. Only for the APIs behind the ProcessXML service URL does Invantive SQL offer filter options.

The processxml API group can be recognized by the service URL containing the value webservices/processxml.asmx, but it is more intuitive to ask yourself whether many rows can be returned and whether the rows change when transactions are processed? If the answer to both is yes, then it will be a table from the processxml API group.

Filters

Given the large volumes of data, it is useful and sensible in SQL queries to include filters so that:

  • the Twinfield API server has to do as little work as possible to select the data in the administration,
  • the financial data comes back quickly and
  • the network is not overloaded.

In the SQL code, filters can be included after where that limit the amount of data, such as all bookings in period 4 of 2019:

select *
from   generalledgerdetails
where  FIN_TRS_HEAD_YEARPERIOD = '2019/04'

Forwarding Filter to Twinfield API Server

Not every filter is forwarded to Twinfield: the query above on GeneralLedgerDetails does use a filter on year/period, as visible when retrieving via SessionIOs@DataDictionary:

Filters used on Twinfield API

But the functionally identical query:

select *
from   generalledgerdetails
where  fin_trs_head_year = 2019
and    fin_trs_head_period = 4

does not use filters, so first all documents must be retrieved and filtered locally:

Twinfield query without filter

Invantive SQL itself determines which filters, possibly after a transformation, can be forwarded to the Twinfield API servers. This is called “server-side filtering”. More information on this can be found in How to filter data from OData query on Azure Data Factory? - 3 from forums.

On most platforms, server-side filtering works automatically because it is hardcoded in the code or the metadata specifies which fields can be filtered. For Twinfield, the current Invantive implementation of server-side filtering is impractical because Twinfield does indeed state through the metadata which server-side filters are possible, but also specifies which operator (equals, between values) must be used.

The supported filters can be found in the contents of the Twinfield metadata table TableColumnSpecifications:

Twinfield browser filters

Here, for example, it can be read that a filter with a between can be used for BankTransactions on the field fin_trs_head_yearperiod.

The Twinfield online documentation also contains the list of fields that can be filtered faster, such as the field FIN_TRS_HEAD_NUMBER with a between, >=, >, =, < or <=:

CashTransactions (Twinfield)

Cash Transactions

documentation.invantive.eu

Rewrite Query

Invantive SQL is smart enough to also translate the Invantive SQL equality operator for Twinfield into a Twinfield between, so for example a query such as:

select *
from   banktransactions
where  fin_trs_head_yearperiod = '2019/01'

uses a Twinfield between filter operator on fin_trs_head_yearperiod. This can also be read in SessionIOs@DataDictionary, where the Invantive notation is shown:

FIN_TRS_HEAD_YEARPERIOD Equals 2019/01, fin.trs.head.banktype equal bank

More details can also be found in the trace, as explained in How do I get trace files again from an automated download with Data Hub? - 2 from forums. The native call log shows all details as described in Collect Native Platform Call Data.

Summary

Even large to very large Twinfield administrations can easily be processed in Invantive SQL or replicated to a database by formulating the right filters in an Invantive SQL where clause.

Reply on the forum