Create a function that checks if ID number satisfies criteria

aquincoaquinco 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!!!

Answers

  • RockWithNAVRockWithNAV Member Posts: 1,139
    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.
  • aquincoaquinco Member Posts: 16
    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? :(
  • RockWithNAVRockWithNAV Member Posts: 1,139
    You may either choose Code or Text data type.

    What code you want you to write in your custom Function, please elaborate a bit.
  • aquincoaquinco Member Posts: 16
    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
    :D

    If my code is ABCDEFGHIJ :)
    THANKS!
  • Wisa123Wisa123 Member Posts: 308
    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 Dev
  • aquincoaquinco Member Posts: 16
    Hello Visa. As you can see, I did everything as shown but it gives me error like one in the last pic. Did I chose data types wrong? :((((((
    2.PNG 15.3K
    3.PNG 21.9K
    4.PNG 23.7K
  • aquincoaquinco Member Posts: 16
    UMCN is my ID field
  • Wisa123Wisa123 Member Posts: 308
    textVar should be of type text. i guess your code fails at line 1 in your screenshot :)
    Austrian NAV/BC Dev
Sign In or Register to comment.