Tuesday, January 13, 2015

Delete the Tab and Carriage-return character from text in Dynamics NAV

Hi,

In NAV there is often an issue with invalid characters when a user is using copy&paste with external programs. For instance when copying data from Excel. Fields that comes to my mind is address-fields on Customer and Vendor cards etc.

When using copy&paste the copied data often also contain hidden whitespaces like carriage-return (0×13 0×10).

When exporting this data to files, or when using data in integrations projects, these characters can be annoying, causing the output to be malformed.

An even worse case is when the user is using  “copy&paste” to enter serial no into NAV.

When later someone tries to do a search on a serialno, there user must user a wildcard-search to find the record.

For instance, a user pastes a serial no ‘ABC123′ from a list in Word/Excel. The invalid character is not visible when running NAV on Win7. On Win XP there is a ’square’-character. To find the record the user must search for ‘ABC123*’, instead of ‘ABC123′.

So, here’s the solution.
Create the following function and call it in your code










CRLF_lTxt[1] := 10;
CRLF_lTxt[2] := 13;
InputTxt_vTxt := DELCHR(InputTxt_vTxt,'<>',CRLF_lTxt);

====================================================
Delete TAB keyword  & New Line Character from data

RemoveHiddenCharacters(VAR ValueToClean : Text) 
Var
  Ch - Text 3
Begin
  Ch[1] := 9 ;  - TAB
  Ch[2] := 13 ; - CR - Carriage Return 
  Ch[3] := 10 ; - LF - Line Feed
  ValueToClean := DELCHR(ValueToClean,'=',ch) ;

End;

==================================================================

1 comment:

  1. Sometime few educational blogs become very helpful while getting relevant and new information related to your targeted area. As I found this blog and appreciate the information delivered to my database.
    HPE WinServ 2016 Standard 16C

    ReplyDelete