Input check for text and code fields in NAV

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.

In cu 1 there is a function called “MakeText” (function no 107). This function is called whenever users enter data to a text-field. If we clean the incoming data in this function, we will not have any issues with address-fields etc.

Serial number are of data type CODE and will not be handled by this function.

If we create a new function “MakeCode” (function no 109), we have solved the problem with CODE-fields to. Below you find the code-changes made to cu 1.

Please note that function 109 is not implemented by default. I don’t know if this feature is supported by Microsoft.

However, I’ve been using it on several sites for years now..

cu 1:...PROCEDURE MakeText@107(VAR Text@1000 : Text[250]) : Integer;
VAR
Position@1004 : Integer;
Length@1003 : Integer;
BEGIN
//START
Text := CleanCRLF(Text);
//END
Position := 1;
Length := STRLEN(Text);
ReadCharacter(’ ‘,Text,Position,Length);
IF NOT ReadSymbol(’?',Text,Position,Length) THEN
EXIT(0);
PartOfText := COPYSTR(Text,Position);
IF PartOfText = ” THEN BEGIN
IF FORM.RUNMODAL(0,StdTxt) = ACTION::LookupOK THEN
Text := StdTxt.Description;
EXIT(0);
END;
StdTxt.Code := COPYSTR(Text,Position,MAXSTRLEN(StdTxt.Code));
IF NOT StdTxt.FIND(’=>’) OR
(UPPERCASE(PartOfText) <> COPYSTR(StdTxt.Code,1,STRLEN(PartOfText)))
THEN
EXIT(Position);
Text := StdTxt.Description;
EXIT(0);
END;
...

..and the new functions....

PROCEDURE MakeCode@109(VAR Text@1000 : Text[250]) : Integer;
BEGIN
Text := CleanCRLF(Text);
EXIT(0);
END;

PROCEDURE CleanCRLF@1070000(Text@1070000 : Text[250]) : Text[250];
VAR
CRLF@1070001 : Text[2];
BEGIN
CRLF[1] := 10;
CRLF[2] := 13;
EXIT(DELCHR(Text,’<>’,CRLF));
END;

4 Responses to “Input check for text and code fields in NAV”

  1. sankar Says:

    very useful one thanks for sharing

  2. Input check for text and code fields in NAV | Pardaan.com Says:

    […] Bron : Yet another NAV blog Lees meer… […]

  3. NAVman Says:

    MakeText() mods make sense, just not sure about MakeCode() - how do you tell NAV to call it from a code field?!

  4. rola Says:

    It doesn’t matter what you call the function. The key is to set it to function no 109.
    Trigger 109 in Cu1 is triggered globaly whenever a CODE-field is validated.

Leave a Reply

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word