Create a function that checks if ID number satisfies criteria

aquinco
Member Posts: 16
Hi everyone 
I'm new into NAV so maybe my question will seem a bit noob but here it goes.
I created a table which has a field called ID number where user needs to enter a 10-digit integer which represents his/her's ID.
I must create a function that will check if this number is correct by checking if it satisfies following criteria:
If number is ABCDEFGHIJ, then digit J (which is called control digit) must be equal to:
J=13-( 7*(A+G) + 6*(B+H) + 5*(C+I) + 4*(D+J)) MOD 13
and also, needs to satisfy criteria below:
J <= 9 -> X = J
J > 9 -> X = 0
I thought using function FORMAT first to convert integer to string and then COPYSTR for each of local variables A,B,C,D... but it doesn't work
Can anyone please help me out with correct code?
THANK YOU IN ADVANCE!!!

I'm new into NAV so maybe my question will seem a bit noob but here it goes.
I created a table which has a field called ID number where user needs to enter a 10-digit integer which represents his/her's ID.
I must create a function that will check if this number is correct by checking if it satisfies following criteria:
If number is ABCDEFGHIJ, then digit J (which is called control digit) must be equal to:
J=13-( 7*(A+G) + 6*(B+H) + 5*(C+I) + 4*(D+J)) MOD 13
and also, needs to satisfy criteria below:
J <= 9 -> X = J
J > 9 -> X = 0
I thought using function FORMAT first to convert integer to string and then COPYSTR for each of local variables A,B,C,D... but it doesn't work

Can anyone please help me out with correct code?
THANK YOU IN ADVANCE!!!
0
Answers
-
Hey aquinco,
Pardon to ask but the question is yet not clear to me - You said you have created a Table with Field ID where users are supposed to enter an Integer value with 10 digit.
Now what you have selected the data type for this integer value? If it's integer then integer ranges from -2,147,483,647 to 2,147,483,647. So what if user is entering an Integer value of 10 digit greater then 2,147,483,647.
Now you wrote If number is ABCDEFGHIJ,, If it's an integer value how it could be ASBDEFGHIJ??
Let me know if I misunderstood something.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Yes, you are right
I meant BigInteger or even maybe Code data type. This is not of great imprtance for me since these IDs customerswill be entering all begin with 01, 02, 03...21. But when I think of it, it would maybe be better to use Code data type. Correct me if I am wrong
Can this code be written for my custom function?
0 -
You may either choose Code or Text data type.
What code you want you to write in your custom Function, please elaborate a bit.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Well, the code I mentioned, that will check if the last digit of this code satisfies the formula J=13-( 7*(A+G) + 6*(B+H) + 5*(C+I) + 4*(D+J)) MOD 13
If my code is ABCDEFGHIJ
THANKS!0 -
ID - OnValidate
textVar := format(ID);
IF NOT STRLEN(textVar) = 10 THEN
ERROR('I need 10 digits, buddy');
EVALUATE(intArr[1],textVar[1]);
....
....
EVALUATE(intArr[10],textVar[10]);
intHelper = 13-(7*(intArr[1] + intArr[6] .......... ; //your formula
if inthelper <> intArr[10] then
error('checksum wrong!')
Of course assuming your ABCDEFGHIJ are actual numbers and you just used the letters to point out your problem.
Austrian NAV/BC Dev0 -
UMCN is my ID field0
-
textVar should be of type text. i guess your code fails at line 1 in your screenshotAustrian NAV/BC Dev0
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