I'm experiencing a problem that I didn't think would occur. I'm using NAV 2009 SP1 with SQL 2008 and wrote a dataport that reads data and inserts it into the Sales Line table after inserting the Sales Header record. When I finish inserting my data, I run the following code:
SalesHeader.RESET;
SalesHeader.SETRANGE("Document Type",SalesHeader."Document Type"::Invoice);
SalesHeader.SETRANGE("Posting Date",BusinessDate);
SalesHeader.SETFILTER("No.","Store ID" + '*');
IF SalesHeader.FINDSET THEN REPEAT
SalesHeader.CALCFIELDS(Amount);
IF SalesHeader.Amount <> 0 THEN BEGIN
// do some stuff to bring the invoice balance to zero
END;
UNTIL SalesHeader.NEXT = 0;
The problem is that the SalesHeader.Amount is always zero within the dataport but can be non-zero after the dataport finishes. So I suspect that the CALCFIELDS is not able to work on uncommitted data. I was under the impression that I did not need a COMMIT to read data that I previously wrote in my own code. Is this not true?
I have not tested my theory by adding a COMMIT yet because I don't have an up-to-date test database prepared.
Thanks.
Answers
http://www.BiloBeauty.com
http://www.autismspeaks.org
My Blog - nav.education
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
Really? Under what circumstance do you see that? :-k
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
Or are you recommending that I manually add up all of the detail lines (using Line Amount)?
to calculate the document amount without releasing it I figured that you have to do what the statistics window does do calculate the amount.
For example, the following function calculates the amounts including VAT:
That's more or less what the statistics window is doing in OnOpenForm(). Works fine when you need to show the total amount of all documents in a list form. The problem you experience with the Sales Header.Amount field has nothing to do with uncommited data.
with best regards
Jens
Sorry, no. I didn't see you were only grabbing the information from the Sales Header table.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
When an order is released, the system populates the Amount field on the lines, and when the order is re-opened, the system sets those fields back to 0, at least that is what is *supposed* to happen.
My guess is that orders that show 0 Amount on the header are simple not released, and the ones that do, are. If that's not the case, or if the totals do not add up correctly, then there is something wrong with your release process.
I also doubt that this has anything to do with (un)committed data.
RIS Plus, LLC
I am not releasing the document so, naturally, the Amount field is going to be zero. What I want to look at in this case is "Outstanding Amount ($)", which gives me what I need.
Thanks again!