NAV 2017 - Customize Code Problem in Report

AlexLim
Member Posts: 16
Dear Nav Expert,
I have tried to find any related post about my question, however i have no luck as I not even know what keyword I should use, sorry if got similar post.
Back to question, recently I tried to add additional column in report, named as "No." and it show report line no.(example 1, 2 3... etc). You may check the sample I attached.
I use my own customize code to handle in VB(I simply don't like to pass many value from Nav to VB
). However some odd thing happen. When I print or preview with multiple document, result show exactly same and "No." work as i expected. But when i print in PDF or direct printer in single document, its show 4,5,6 instead of 1,2,3, more weird is preview, word and excel work correctly.
Not sure how to upload my work so i write the code here.
{ //This code is writen in VB Code
Shared LineNo as Integer
Shared ExDocNo as String
Public Function GetLineNo (CurDocNo as String)
If ExDocNo <> CurDocNo then
LineNo = 1
ExDocNo = CurDocNo
else
LineNo = LineNo + 1
End if
Return LineNo
End Function
}
{//And This code is added in new column, before Item No.
=Code.GetLineNo(Fields!No_SalesInvHdr.Value)
}
Is anyone have idea what happen? Is my code not correct or something?
Thank you.
Best Regards,
Alex
I have tried to find any related post about my question, however i have no luck as I not even know what keyword I should use, sorry if got similar post.
Back to question, recently I tried to add additional column in report, named as "No." and it show report line no.(example 1, 2 3... etc). You may check the sample I attached.
I use my own customize code to handle in VB(I simply don't like to pass many value from Nav to VB

Not sure how to upload my work so i write the code here.
{ //This code is writen in VB Code
Shared LineNo as Integer
Shared ExDocNo as String
Public Function GetLineNo (CurDocNo as String)
If ExDocNo <> CurDocNo then
LineNo = 1
ExDocNo = CurDocNo
else
LineNo = LineNo + 1
End if
Return LineNo
End Function
}
{//And This code is added in new column, before Item No.
=Code.GetLineNo(Fields!No_SalesInvHdr.Value)
}
Is anyone have idea what happen? Is my code not correct or something?
Thank you.
Best Regards,
Alex
0
Best Answer
-
May be you should set LineNo to zero at a more appropriate place in the report (for example within the SetData tablix), because it looks like, that the LineNo textbox is rendered more than once in the case of PDF output. Furthermore, LineNo should also be set to zero, when a new copy of a document starts.
As has already been proposed, it is more easy to set LineNo from within C/AL-code and pass it as a field to the report layout. Of course, LineNo := 0; should not be in the OnInitReport trigger, but in the CopyLoop-OnAfterGetRecord trigger and the increment instruction LineNo += 1; should be in the Sales Invoice Line - OnAfterGetRecord trigger confined to the case, where Type and No. are both not zero or empty, respectively.New kits on the blog: https://massivedynamicsblog.wordpress.com6
Answers
-
I advise all the calculations to carry out in DEV.
Global variable: LineNo integer
OnInitReport():
LineNo := 0;
SalesInvHdr - OnAfterGetRecord():
LineNo +=1;
Then LineNo determine for Layout.
GL0 -
May be you should set LineNo to zero at a more appropriate place in the report (for example within the SetData tablix), because it looks like, that the LineNo textbox is rendered more than once in the case of PDF output. Furthermore, LineNo should also be set to zero, when a new copy of a document starts.
As has already been proposed, it is more easy to set LineNo from within C/AL-code and pass it as a field to the report layout. Of course, LineNo := 0; should not be in the OnInitReport trigger, but in the CopyLoop-OnAfterGetRecord trigger and the increment instruction LineNo += 1; should be in the Sales Invoice Line - OnAfterGetRecord trigger confined to the case, where Type and No. are both not zero or empty, respectively.New kits on the blog: https://massivedynamicsblog.wordpress.com6 -
Hi Dolsha & gerdhuebner,
Thank for reply and sorry I late reply.
The solution provided actually I used to use, but I have this idea is start from when I customize a report that required different type of sorting that cannot find in table key, and i not allow to add new key for sorting or simply add new key is too much since only use in 1 report.
And that the problem come in, if the report have no. Then the output become not in sequence i wanted.
As I know the sorting only can done in 2 way, key or VB. Of course this question have solution since very beginning, but just wanted know is any other option.
Edit :
gerdhuebner, your solution is worked, I add some simple reset code in setdata table, and its reset to no i wanted. Thank you very much.
But just not understand, why its only happen in single document print out?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