Leading Zeros in Dataport

pengweninc
Member Posts: 38
I have a right justified field on a dataport export. I need leading zeros to the left of the field and I'm not sure how to do it.
Right now the field exports like this:
12345
12346
12347
I need it to look like:
012345
012346
012347
Right now the field exports like this:
12345
12346
12347
I need it to look like:
012345
012346
012347
0
Comments
-
You can use format command on the trigger onBeforeExport, for example
myStr := FORMAT(myInt,0,'<Integer,6><Filler Character,0>')
Hope this helps
Thomas0 -
I should have mentioned, this number is actually a code, not an integer.0
-
I have used this one
"myString" := PADSTR('',MAXSTRLEN("myString")-STRLEN("myString"),'0') + "myString";
to fill in only "needed" zeros (which came from length of myString).Tomas,
Dynamics NAV Enthusiast0 -
In this case you have 2 possibilities:
1) Convert the code to a number, then use format as mentioned
2) prefix a string of 6 zeroes to the code and use the 6 rightmost characters only, in this case the padding to 6 should be ok. Maybe there is an easier way, but it works anyway...
Hope this helps
Thomas0 -
I have just tried with code
Name DataType Subtype Length myCode Code 10
myCode := '1234'; myCode := PADSTR('',MAXSTRLEN(myCode)-STRLEN(myCode),'0') + myCode; MESSAGE('%1',myCode);
returns 0000001234Tomas,
Dynamics NAV Enthusiast0 -
That did the trick! Perfect, thank you.0
-
anyway...format works,too
cd := '1234' message(format(cd,0,'<Text,5><Filler Character,0>'));
<Text,5> insert the lenght of the string you want
but be careful: if the variable is text instead of code (or the code contains a letter or symbol), the 0s will be trailing instead of leading0
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