FORMAT(); Used for Phone Numbers?

XypherXypher Member Posts: 297
Anyone know if I can use FORMAT() function to display 10+ digits as:

(XXX)XXX-XXXX or XXX-XXX-XXXX ?


(I have just started working in NAV two weeks ago, so I am still learning. I tried looking up all the information I could find on FORMAT but could not identify whether or not I would be able to complete this task.)

Answers

  • ara3nara3n Member Posts: 9,256
    Hello There is no format function for phone no.

    I usually add this code
    Phone No. - OnValidate()
    //T01 Start
    IF GUIALLOWED AND (CurrFieldNo = FIELDNO("Phone No.")) THEN BEGIN
      IF  STRLEN("Phone No.") < 10 THEN
        ERROR('Please Enter at least 10 Digit number');
    END;
    IF ("Phone No." <> '') AND (STRLEN("Phone No.") >= 10) THEN BEGIN
      TempStr := '';
      FOR I := 1 TO STRLEN("Phone No.") DO BEGIN
        IF EVALUATE(TempInt,FORMAT("Phone No."[I])) THEN
          TempStr += FORMAT("Phone No."[I]);
      END;
      IF GUIALLOWED AND (CurrFieldNo = FIELDNO("Phone No.")) THEN BEGIN
        IF NOT (STRLEN(TempStr) IN [10,12,13]) THEN
          ERROR('Please Enter 10 or 12 or 13 Digit number');
      END;
    
      IF STRLEN(TempStr) = 10 THEN
        "Phone No." := '(' + COPYSTR(TempStr,1,3) + ')-' + COPYSTR(TempStr,4,3) + '-'+COPYSTR(TempStr,7);
      IF STRLEN(TempStr) = 13 THEN
         "Phone No." :=  COPYSTR(TempStr,1,3) + '-' + COPYSTR(TempStr,4,3) + '-'+ COPYSTR(TempStr,7,3) + COPYSTR(TempStr,10);
      IF STRLEN(TempStr) = 12 THEN
         "Phone No." :=  COPYSTR(TempStr,1,2) + '-' + COPYSTR(TempStr,3,3) + '-'+ COPYSTR(TempStr,6,3) + COPYSTR(TempStr,9);
    
    END;
    
    //T01 End
    
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    The Variable
    Name	DataType	Subtype	Length
    TempStr	Text		30
    I	Integer		
    TempInt	Integer		
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • XypherXypher Member Posts: 297
    Thank you for the answer.

    Although, no offense, I think I can whip up a little bit cleaner and refined code to do the job. :D
  • ara3nara3n Member Posts: 9,256
    Please do and post the code.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • XypherXypher Member Posts: 297
    Well I suppose not refined or very clean looking...

    (Text field set 'AllowChar: 09--')
    ValidatePhoneNumber(PhoneNumber : Text[30]) : Text[30]
    IF STRLEN(PhoneNumber) > 0 THEN BEGIN
      PhoneNumber := DELCHR(PhoneNumber,'=','-');
      PhoneNumber := DELCHR(PhoneNumber,'=',' ');
    
      IF PhoneNumber[1] = '1' THEN
        PhoneNumber := COPYSTR(PhoneNumber,2);
    
      IF STRLEN(PhoneNumber) < 10 THEN
        FOR Count := 1 TO (10 - STRLEN(PhoneNumber)) DO
          PhoneNumber += '?';
    
      PhoneNumber := COPYSTR(PhoneNumber,1,3) + '-' + COPYSTR(PhoneNumber,4,3) + '-' +
                     COPYSTR(PhoneNumber,7);
    
      IF STRLEN(PhoneNumber) > 12 THEN
        PhoneNumber := COPYSTR(PhoneNumber,1,12) + ' ' + COPYSTR(PhoneNumber,13);
    
    END;
    
    EXIT(PhoneNumber);
    
  • ara3nara3n Member Posts: 9,256
    Try to call your function with

    '(234) 567-8900'
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • XypherXypher Member Posts: 297
    ara3n wrote:
    Try to call your function with

    '(234) 567-8900'

    You wouldn't be able to, since AllowChar is set to: 09--
  • ara3nara3n Member Posts: 9,256
    missed that.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    btw what company are you working in VA?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • XypherXypher Member Posts: 297
    SimplyWireless
  • ara3nara3n Member Posts: 9,256
    How are they doing?

    Is the replication working for them?

    Is Marty still taking care of everything?

    I wrote all the code modification for the POS. I'm guessing you've been cleaning that up?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • XypherXypher Member Posts: 297
    I believe they are doing quite well since they've been buying up quite a bit of stores on the east coast.

    Replication still appears to be quite a task for them.

    As far as Marty goes, not sure, since I am in an office all by myself I don't see much of what's going on around.


    So far I've been working on initial training and small projects, since it was only 3 weeks ago that I first ever heard of NAV.
  • ara3nara3n Member Posts: 9,256
    How many location do they have now? and how big is their db?
    Last Time I checked it was reaching 50 gig, and they were trying to setup on SQL 2k5 mirroring and they were running out of space.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.