I have created a dataport that accumulates total count and amount of checks and exports to a text file. I only need to export the last record. I am currently using the following code in the OnBeforeExport() trigger section, but I get a blank file:
TotalAmount := TotalAmount + Amount;
TotalDetailRecs := TotalDetailRecs + 1;
IF NEXT<>0 THEN CurrDataport.SKIP;
It exports correctly without the NEXT SKIP line, I just don’t need all the other lines. Any ideas?
Change your dataitem to the Integer table (be sure to filter Number=1), define your present dataitem as a record variable, calculate your values and let the dataport write them out.
Thanks, Anna. I appreciate the response. I’ve tried to make this work, but I must be missing something. I’m not clear on how to use the record variable concept. Is there an example you can direct me to that might help make it clearer? Again, thanks.
I do have one other question regarding this. I would like to set this dataport up to use a request form so the user can select a specific group of reocrds by date range. I’ve added the table as a dataitem (non-indented under the Integer dataitem with the date field specified in ReqFilterFields) and it comes up as a request form, but it’s not filtering any records. Can you tell me what i’m missing here? Again, thanks.
Mhmm… no, you cannot do it that way. The filter set by the user will apply to the dataitem, but you need it on the global variable. The fact that they are the same table does not matter - they are two different variables and they are seen as two separated entities.
So we need a different solution! [:)]
To add your table as a dataitem with the date field in ReqFilterFields is ok, but put it over, not under the Integer dataitem.
You may leave everthing else as it is, but the code in the OnBeforeExportRecord for Integer dataitem will now start with the following line:
MyRecord.COPYFILTERS(“The table you defined as the first dataitem”);
This line will copy any filter the user will set on the new dataitem to the global variable that you are actually processing.
This might not be the most elegant solution, but should work and requires a minimum of canghes from what you already did.
Thanks again, we are SOOO close. Filters are working, but the file now has a blank line for every record that is accumulated. The attached example is the output for a filtered date that consists of 3 records. How do we get rid of the blanks?
Oooops, sorry, I forgot to tell you this. Of course, you are getting a blank record for each record of the table, because you are actually processing it as a dataitem.
To prevent this you must add some code to the first dataitem (not the Integer, the other one!):
In OnPreDataport trigger:
CurrDataport.BREAK;
This will imediately stop the process on that table and go ahead to the Integer dataitem
That did it, seems to be working great now! Thanks so much for your help and patience, Anna!
Thanks to Matt as well for your suggestion. As a relative newcomer to the NAV product, it’s nice to know that such helpful folks are out there.
As an aside, can anyone recommend a definitive reference for programming in NAV? I’m using the Application Design Guide and David Studebaker’s Programming Microsoft Dynamics NAV, but there seems to be a lot of concepts that aren’t covered very well in those references (use of virtual tables, for example). I’d appreciate any suggestions. Thanks again to everyone.