Announcements
Hi,
I am trying to write job to display an Infolog of all customers with an open balance greater than 5,000 in the customer currency and display the balance in the customer and master company currency.
How to get this.
regards,
Srinivas Pamidi
*This post is locked for comments
Easy enough to fix. Just use CustTrans instead of CustTransOpen, and filter on TransDate <= Assessment date.
@Brandon
That's faster if we don't need Assessment Date, because you dropped a half of the method.
This is even faster using a single set based operation, but still uses a CrossCompany query.
Query q; QueryBuildDataSource qbds; QueryRun qr; QueryHavingFilter qhf; CustTable custTable; CustTransOpen custTransOpen; ; q = new Query(); q.allowCrossCompany(true); qbds = q.addDataSource(tableNum(CustTable)); qbds.addGroupByField(fieldNum(CustTable, DataAreaId)); qbds.addGroupByField(fieldNum(CustTable, AccountNum)); qbds = qbds.addDataSource(tableNum(CustTransOpen)); qbds.relations(true); qbds.addSelectionField(fieldNum(CustTransOpen, AmountMST), SelectionField::Sum); qbds.orderMode(OrderMode::GroupBy); qhf = q.addHavingFilter(qbds, fieldStr(custTransOpen, AmountMST), AggregateFunction::Sum); qhf.value('> 5000'); qr = new QueryRun(q); while (qr.next()) { custTable = qr.get(tableNum(CustTable)); custTransOpen = qr.get(tableNum(custTransOpen)); info(strFmt("Company: %1, Account number: %2, Open balance: %3", custTable.dataAreaId, custTable.AccountNum, custTransOpen.AmountMST)); }
This is faster than using the openBalance method in a CustTable loop.
The disadvantage of a CrossCompany query is that users will only see customers for which they have access. Looping through DataArea and using changeCompany(..) ignores user security.
CustTable custTable; CustTransOpen custTransOpen; ; while select crossCompany DataAreaId, AccountNum from custTable group DataAreaId, AccountNum join sum(AmountMST) from custTransOpen where custTransOpen.AccountNum == custTable.AccountNum { if (custTransOpen.AmountMST > 5000) { info(strFmt("Company: %1, Account number: %2, Open balance: %3", custTable.dataAreaId, custTable.AccountNum, custTransOpen.AmountMST)); } }
DataArea dataAread; CustTable custTable; while select id from dataAread where !dataAread.isVirtual { changecompany(dataAread.id) { custTable = null; while select custTable { if (custTable.openBalanceCur() > 5000) { info(strFmt("%1,%2,%3", custTable.AccountNum, custTable.openBalanceCur(),custTable.Currency)); } } } }
Now it is working changing code like this
while select custTable
{
if (custTable.openBalanceCur() > 5000)
{
info(strFmt("%1,%2,%3", custTable.AccountNum, custTable.openBalanceCur(),custTable.Currency));
}
}
but how to run this job in cross company?
Hi
i am writing like this but info log is not open
while select custTable
{
if (custTable.openBalanceCur(fromDate, toDate, assessmentDate, custTable.Currency) > 100)
{
info(strFmt("%1,%2", custTable.AccountNum, custTable.openBalanceCur()));
}
}
Hi srinivas,
You can try something like
while select custTable { if (custTable.openBalanceCur(froamDate, toDate, assessmentDate, custTable.Currency)) > 5000) { //info(); } }
André Arnaud de Cal...
294,217
Super User 2025 Season 1
Martin Dráb
232,978
Most Valuable Professional
nmaenpaa
101,158
Moderator