CALCFIELDS does not work with CHANGECOMPANY

kanika
Member Posts: 247
Hi Experts!!
NAV2018, shared customer table for all companies
In a report I need to put the client balance per company,for which I have a temporary table, but the value only calculates it to me correctly for the first company, for the rest it leaves the same value and does not recalculate it, this is my code:
pCompany.RESET;
IF pCompany.FINDFIRST THEN REPEAT
pCustomer.RESET;
pCustomer.CHANGECOMPANY(pEmpresa.Name);
IF pCustomer.FINDFIRST THEN REPEAT
pCustomer.CALCFIELDS("Balance (LCY)");
IF pCustomer."Balance (LCY)"<>0 THEN BEGIN
pSaldos.INIT;
pSaldos.Empresa:=pCompany."Display Name";
pSaldos.NIF:=pCustomer."VAT Registration No.";
pSaldos.Nombre:=pCustomer.Name;
pSaldos."Saldo Deudor":=pCustomer."Balance (LCY)";
pSaldos.INSERT(TRUE);
END;
UNTIL pCustomer.NEXT=0;
UNTIL pCompany.NEXT=0;
Any ideas? thanks in advance
NAV2018, shared customer table for all companies
In a report I need to put the client balance per company,for which I have a temporary table, but the value only calculates it to me correctly for the first company, for the rest it leaves the same value and does not recalculate it, this is my code:
pCompany.RESET;
IF pCompany.FINDFIRST THEN REPEAT
pCustomer.RESET;
pCustomer.CHANGECOMPANY(pEmpresa.Name);
IF pCustomer.FINDFIRST THEN REPEAT
pCustomer.CALCFIELDS("Balance (LCY)");
IF pCustomer."Balance (LCY)"<>0 THEN BEGIN
pSaldos.INIT;
pSaldos.Empresa:=pCompany."Display Name";
pSaldos.NIF:=pCustomer."VAT Registration No.";
pSaldos.Nombre:=pCustomer.Name;
pSaldos."Saldo Deudor":=pCustomer."Balance (LCY)";
pSaldos.INSERT(TRUE);
END;
UNTIL pCustomer.NEXT=0;
UNTIL pCompany.NEXT=0;
Any ideas? thanks in advance
0
Best Answer
-
You have to "calc" balance in Customer Ledger Entry table manually.5
Answers
-
Hi Experts!!
NAV2018, shared customer table for all companies
In a report I need to put the client balance per company,for which I have a temporary table, but the value only calculates it to me correctly for the first company, for the rest it leaves the same value and does not recalculate it, this is my code:
pCompany.RESET;
IF pCompany.FINDFIRST THEN REPEAT
pCustomer.RESET;
pCustomer.CHANGECOMPANY(pEmpresa.Name);
IF pCustomer.FINDFIRST THEN REPEAT
pCustomer.CALCFIELDS("Balance (LCY)");
IF pCustomer."Balance (LCY)"<>0 THEN BEGIN
pSaldos.INIT;
pSaldos.Empresa:=pCompany."Display Name";
pSaldos.NIF:=pCustomer."VAT Registration No.";
pSaldos.Nombre:=pCustomer.Name;
pSaldos."Saldo Deudor":=pCustomer."Balance (LCY)";
pSaldos.INSERT(TRUE);
END;
UNTIL pCustomer.NEXT=0;
UNTIL pCompany.NEXT=0;
Any ideas? thanks in advance
it should be pCompany.Name
0 -
i second vijay_g's answer.
side note: "IF xyz.FINDFIRST THEN REPEAT" is bad practise. Use "IF xyz.FINDSET THEN REPEAT" for better performance.
Reason: If you want to loop through several records, "findset" is made to get a few of them into the NSTs buffer for faster processing. With Findfirst, your NST doesn't expect you to need more than one record so it will only ask the SQL server for the "top 1" and i guess it will repeat that practise with every "next".
If you don't belive me, please read the "remarks"-Section of those two functions in the help.1 -
yes vijay_g you're right, I translated it wrong
but in the code is well placed0 -
StLi , I belive you!!0 -
You cannot use a flowfield after a changecompany instruction. It will calculate everything with the data contained in your "CURRENTCOMPANY".
Same behaviour with validates.Giving thanks is always wellcome0 -
You have to "calc" balance in Customer Ledger Entry table manually.5
-
Thanks everyone for your help!
lubost, that's what I did and it works perfectly0 -
it happened to me a calcsums for ledger entries did not work, no clue why, it was retrieving records from other companies and at the end I had to do sum+=value sadly.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions