web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Length of the string Error Message

(0) ShareShare
ReportReport
Posted on by 195

Dear Developers:

I wrote a code to convert the text to base64 in order to convert it to a QR code for sale transactions details, I got a problem when we post the transaction (on pos Ls NAV) an error message:

"The length of the string is 30, but it must be less than or equal to 20, the value is 'the base64 string value of 30 characters length'"

I checked all the variables in my code, all are 1024 length.

Anybody help.

I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,423 Super User 2026 Season 1 on at

    hi

    could you attach your code?

    DAn

  • Family Corner Profile Picture
    195 on at

    This is the code of Getting the QR:

    OBJECT Codeunit 50005 QR Code Management POS

    {

     OBJECT-PROPERTIES

     {

       Date=11/10/22;

       Time=10:40:33 AM;

       Modified=Yes;

       Version List=FC-MGA;

     }

     PROPERTIES

     {

       TableNo=99001472;

       OnRun=VAR

               CompanyInfo@1170000004 : Record 2000000006;

               TransactionHeader@1170000003 : Record 99001472;

               TempBlob@1170000002 : Record 99008535;

               QRCodeInput@1170000000 : Text[1024];

               QRCodeFileName@1170000001 : Text[1024];

             BEGIN

               TransactionHeader := Rec;

               QRCodeInput:=CreateQRCodeInput(FORMAT(TransactionHeader.Date,0,9),' '+FORMAT(TransactionHeader.Time,5,9),FORMAT(TransactionHeader.Payment,0,'<Precision,2:2><Standard Format,9>'),

               FORMAT(-1*(TransactionHeader."Gross Amount" -  TransactionHeader."Net Amount"),0,'<Precision,2:2><Standard Format,9>'));

               myInteger:=STRLEN(QRCodeInput)/2;

               QRCodeInput:=UPPERCASE(QRCodeInput);

               QRCodeInput:=HexToBinary(QRCodeInput);

               QRCodeInput:=Base64Converter.ConvertBinaryValueToBase64String(QRCodeInput,myInteger);

               QRCodeFileName := GetQRCode(QRCodeInput);

               QRCodeFileName := MoveToMagicPath(QRCodeFileName); // To avoid confirmation dialogue on RTC

               // Load the image from file into the BLOB field

               CLEAR(TempBlob);

               ThreeTierMgt.BLOBImport(TempBlob,QRCodeFileName);

               IF TempBlob.Blob.HASVALUE THEN BEGIN

                  CompanyInformation.GET();

                  CompanyInformation.Stamp := TempBlob.Blob;

                  CompanyInformation.MODIFY;

               END;

               // Erase the temporary file

               IF NOT ISSERVICETIER THEN

                 IF EXISTS(QRCodeFileName) THEN

                   ERASE(QRCodeFileName);

               //Rec := SalesHeader;

             END;

     }

     CODE

     {

       VAR

         ThreeTierMgt@1170000001 : Codeunit 419;

         CompanyInformation@10014500 : Record 79;

         Base64Converter@10014501 : Codeunit 50050;

         LIntP@10014503 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IntPtr";

         myInteger@10014504 : Integer;

       LOCAL PROCEDURE CreateQRCodeInput@1020046(date@10014500 : Text[20];time@10014501 : Text[20];totalAmntVAT@10014502 : Text[10];VATAmnt@10014503 : Text[10]) QRCodeInput : Text[1024];

       VAR

         tag1@10014504 : Text[80];

         tag2@10014505 : Text[80];

         tag3@10014506 : Text[80];

         tag4@10014507 : Text[80];

         tag5@10014508 : Text[80];

       BEGIN

         //QRCodeInput := 'Order No. : ' + SalesHeaderNo;

         CompanyInformation.GET();

         tag1:=DecimalToHex(1)+DecimalToHex(STRLEN(CompanyInformation.Name))+TextToHex(CompanyInformation.Name);

         tag2:=DecimalToHex(2)+DecimalToHex(STRLEN(CompanyInformation."VAT Registration No."))+TextToHex(CompanyInformation."VAT Registration No.");

         tag3:=DecimalToHex(3)+DecimalToHex(STRLEN(date+time))+TextToHex(date)+TextToHex(time);

         tag4:=DecimalToHex(4)+DecimalToHex(STRLEN(totalAmntVAT))+TextToHex(totalAmntVAT);

         tag5:=DecimalToHex(5)+DecimalToHex(STRLEN(VATAmnt))+TextToHex(VATAmnt);

         QRCodeInput:=tag1+tag2+tag3+tag4+tag5;

         {QRCodeInput := 'Company Name : ' + CompanyInformation.Name + ', ' +

                        'VAT Registraion No. : ' + CompanyInformation."VAT Registration No." + ', ' +

                        'Invoce No. : ' + SalesHeaderNo + ', ' +

                        'Invoce Date : ' + SalesHeaderDate + ', ' +

                        'Invoice Amount Inc. VAT : ' + SalesHeaderAmount + ', ' +

                        'VAT Amount : ' + SalesHeaderVATAmount;}

       END;

       LOCAL PROCEDURE GetQRCode@1020038(QRCodeInput@1020001 : Text[1024]) QRCodeFileName : Text[1024];

       VAR

         IBarCodeProvider@1020000 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.IBarcodeProvider" RUNONCLIENT;

       BEGIN

         GetBarCodeProvider(IBarCodeProvider);

         QRCodeFileName := IBarCodeProvider.GetBarcode(QRCodeInput);

       END;

       PROCEDURE GetBarCodeProvider@1020001(VAR IBarCodeProvider@1020000 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.IBarcodeProvider" RUNONCLIENT);

       VAR

         QRCodeProvider@1020002 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.QRCodeProvider" RUNONCLIENT;

       BEGIN

         QRCodeProvider := QRCodeProvider.QRCodeProvider;

         IBarCodeProvider := QRCodeProvider;

       END;

       PROCEDURE MoveToMagicPath@1170000000(SourceFileName@1170000000 : Text[1024]) DestinationFileName : Text[1024];

       VAR

         FileSystemObject@1170000001 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{0D43FE01-F093-11CF-8940-00A0C9054228}:'Windows Script Host Object Model'.FileSystemObject";

       BEGIN

         // User Temp Path

         DestinationFileName := ThreeTierMgt.ClientTempFileName('');

         IF ISCLEAR(FileSystemObject) THEN

           CREATE(FileSystemObject,TRUE,TRUE);

         FileSystemObject.MoveFile(SourceFileName,DestinationFileName);

       END;

       LOCAL PROCEDURE TextToHex@10014500(TextValue@10014500 : Text) HexStr : Text;

       VAR

         aInt@10014501 : Integer;

         aIndex@10014502 : Integer;

         aLeft@10014503 : Integer;

         aRight@10014504 : Integer;

       BEGIN

         FOR aIndex := 1 TO STRLEN(TextValue) DO BEGIN

           aInt := TextValue[aIndex];

           aLeft := ROUND(aInt / 16,1,'<');

           aRight := aInt MOD 16;

           HexStr += HexValue(aLeft) + HexValue(aRight);

         END;

       END;

       LOCAL PROCEDURE HexValue@10014502(theValue@10014500 : Integer) : Text[1];

       BEGIN

         CASE theValue OF

           0..9: EXIT(FORMAT(theValue));

           10:   EXIT('A');

           11:   EXIT('B');

           12:   EXIT('C');

           13:   EXIT('D');

           14:   EXIT('E');

           15:   EXIT('F');

         END;

       END;

       LOCAL PROCEDURE HexToBinary@10014507(hexStr@10014500 : Text) BinaryStr : Text;

       VAR

         index@10014501 : Integer;

       BEGIN

         FOR index:=1 TO STRLEN(hexStr) DO BEGIN

           //MESSAGE(FORMAT(hexStr[index]));

           BinaryStr+=HexChar(hexStr[index]);

         END;

       END;

       LOCAL PROCEDURE HexChar@10014509(theValue@10014500 : Char) : Text;

       BEGIN

         CASE theValue OF

           '0': EXIT('0000');

           '1': EXIT('0001');

           '2': EXIT('0010');

           '3': EXIT('0011');

           '4': EXIT('0100');

           '5': EXIT('0101');

           '6': EXIT('0110');

           '7': EXIT('0111');

           '8': EXIT('1000');

           '9': EXIT('1001');

           'A': EXIT('1010');

           'B': EXIT('1011');

           'C': EXIT('1100');

           'D': EXIT('1101');

           'E': EXIT('1110');

           'F': EXIT('1111');

          END;

       END;

       LOCAL PROCEDURE DecimalToHex@10014503(decimalValue@10014500 : Integer) HexString : Text;

       BEGIN

         LIntP:=LIntP.IntPtr(decimalValue);

         HexString:=LIntP.ToString('X2');

         //MESSAGE(HexString);

       END;

       BEGIN

       {

         //FC-MGA QR Code Generation

         {QRCodeInput:='0000000100001100010000100110111101100010011100110010000001010010011001010110001101101111'+'0111001001100100011100110000001000001111001100110011000100110000001100010011001'

         +'00011001000110011001110010011001100110101001100000011'+'0000001100000011000000110011000000110001010000110010001100000011001000110010001011010011000'+

         '0001101000010110100110010001101010101010000110001001101010011'+'1010001100110011000000111010001100000011000001011010000001000000011100110001001100000011'+

         '0000001100000010111000110000001100000000010100000110001100010011010100110000001011100011000000110000';}

       }

       END.

     }

    }

  • Family Corner Profile Picture
    195 on at

    Getting Bas64 codeunit:

    OBJECT Codeunit 50050 Base64 Converter

    {

     OBJECT-PROPERTIES

     {

       Date=11/07/22;

       Time=10:33:22 PM;

       Modified=Yes;

       Version List=;

     }

     PROPERTIES

     {

       OnRun=BEGIN

             END;

     }

     CODE

     {

       VAR

         zak@10014500 : DotNet "'Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.Microsoft.CSharp.RuntimeBinder.Binder";

       PROCEDURE TextToBase64String@10014501(Value@10014500 : Text) Base64Str : Text;

       VAR

         length@10014501 : Integer;

         BinaryValue@10014502 : Text;

       BEGIN

         BEGIN

                 // Divide value into blocks of 3 bytes

                 length := STRLEN(Value);

                 BinaryValue := TextToBinary(Value,8);

                //MESSAGE(BinaryValue);

                 Base64Str := ConvertBinaryValueToBase64String(BinaryValue,length);

         END;

       END;

       LOCAL PROCEDURE StreamToBase64String@10014505(value@10014500 : InStream) Base64St : Text;

       VAR

         SingleByte@10014501 : Byte;

         Length@10014502 : Integer;

         BinaryValue@10014503 : Text;

       BEGIN

         BEGIN

                 WHILE NOT value.EOS DO BEGIN

                     value.READ(SingleByte,1);

                     Length += 1;

                     BinaryValue += ByteToBinary(SingleByte,8);

                 END;

                Base64St := ConvertBinaryValueToBase64String(BinaryValue,Length);

         END;

       END;

       LOCAL PROCEDURE FromBase64StringToText@10014510(Value@10014500 : Text) Text : Text;

       VAR

         BinaryValue@10014501 : Text;

       BEGIN

         BEGIN

                 BinaryValue := ConvertBase64StringToBinaryValue(Value);

                 Text := BinaryToText(BinaryValue);

             END;

       END;

       LOCAL PROCEDURE FromBase64StringToStream@10014512(Value@10014500 : Text;VAR Stream@10014501 : OutStream);

       VAR

         BinaryValue@10014502 : Text;

       BEGIN

         BEGIN

                 BinaryValue := ConvertBase64StringToBinaryValue(Value);

                 BinaryToStream(BinaryValue,Stream);

             END;

       END;

       PROCEDURE ConvertBinaryValueToBase64String@10014504(Value@10014500 : Text;Length@10014501 : Integer) Base64Str : Text;

       VAR

         Length2@10014502 : Integer;

         PaddingCount@10014503 : Integer;

         BlockCount@10014504 : Integer;

         Pos@10014505 : Integer;

         CurrentByte@10014506 : Text;

         i@10014507 : Integer;

       BEGIN

         BEGIN

                 IF Length MOD 3 = 0 THEN BEGIN

                     PaddingCount := 0;

                     BlockCount := Length / 3;

                 END ELSE BEGIN

                     PaddingCount := 3 - (Length MOD 3);

                     BlockCount := (Length + PaddingCount) / 3;

                 END;

                 Length2 := Length + PaddingCount;

                 Value := PADSTR(Value,Length2 * 8,'0');

                         // Loop through bytes in groups of 6 bits

                 Pos := 1;

                 WHILE Pos < Length2 * 8 DO BEGIN

                     CurrentByte := COPYSTR(Value,Pos,6);

                     Base64Str += GetBase64Char(BinaryToInt(CurrentByte));

                     Pos += 6;

                 END;

                 // Replace last characters with '='

                 FOR i := 1 TO PaddingCount DO BEGIN

                     Pos := STRLEN(Base64Str) - i + 1;

                     Base64Str[Pos] := '=';

                 END;

             END;

       END;

       LOCAL PROCEDURE ConvertBase64StringToBinaryValue@10014507(Value@10014500 : Text) BinaryTxt : Text;

       VAR

         BinaryValue@10014501 : Text;

         i@10014502 : Integer;

         IntValue@10014503 : Integer;

         PaddingCount@10014504 : Integer;

       BEGIN

         BEGIN

         FOR i := 1 TO STRLEN(Value) DO BEGIN

                     IF Value[i] = '=' THEN

                         PaddingCount += 1;

                     IntValue := GetBase64Number(FORMAT(Value[i]));

                     BinaryValue += IncreaseStringLength(IntToBinary(IntValue),6);

                 END;

                 FOR i := 1 TO PaddingCount DO

                     BinaryValue := COPYSTR(BinaryValue,1,STRLEN(BinaryValue) - 8);

                 BinaryTxt := BinaryValue;

             END;

       END;

       PROCEDURE TextToBinary@10014509(Value@10014500 : Text;ByteLength@10014501 : Integer) BinaryStr : Text;

       VAR

         IntValue@10014502 : Integer;

         i@10014503 : Integer;

         BinaryValue@10014504 : Text;

       BEGIN

         BEGIN

                 FOR i := 1 TO STRLEN(Value) DO BEGIN

                     IntValue := Value[i];

                   //MESSAGE(FORMAT(Value[i]));

                     BinaryValue := IntToBinary(IntValue);

                     BinaryValue := IncreaseStringLength(BinaryValue,ByteLength);

                     BinaryStr += BinaryValue;

                 END;

             END;

       END;

       LOCAL PROCEDURE BinaryToText@10014513(Value@10014500 : Text) TextOutput : Text;

       VAR

         Buffer@10014501 : BigText;

         Pos@10014502 : Integer;

         SingleByte@10014503 : Text;

         CharValue@10014504 : Text;

       BEGIN

         BEGIN

         Buffer.ADDTEXT(Value);

                 Pos := 1;

                 WHILE Pos < Buffer.LENGTH DO BEGIN

                     Buffer.GETSUBTEXT(SingleByte,Pos,8);

                     CharValue[1] := BinaryToInt(SingleByte);

                     TextOutput += CharValue;

                     Pos += 8;

                 END;

             END;

       END;

       LOCAL PROCEDURE BinaryToStream@10014515(Value@10014500 : Text;VAR Stream@10014501 : OutStream);

       VAR

         Buffer@10014502 : BigText;

         Pos@10014503 : Integer;

         SingleByte@10014504 : Text;

         ByteValue@10014505 : Byte;

       BEGIN

         BEGIN

                 Buffer.ADDTEXT(Value);

                 Pos := 1;

                 WHILE Pos < Buffer.LENGTH DO BEGIN

                     Buffer.GETSUBTEXT(SingleByte,Pos,8);

                     ByteValue := BinaryToInt(SingleByte);

                     Stream.WRITE(ByteValue,1);

                     Pos += 8;

                 END;

             END;

       END;

       LOCAL PROCEDURE ByteToBinary@10014517(Value@10014500 : Byte;ByteLenght@10014501 : Integer) BinaryOutput : Text;

       VAR

         BinaryValue@10014502 : Text;

       BEGIN

         BEGIN

                 BinaryValue := IntToBinary(Value);

                 BinaryValue := IncreaseStringLength(BinaryValue,ByteLenght);

                 BinaryOutput := BinaryValue;

             END;

       END;

       LOCAL PROCEDURE IntToBinary@10014519(Value@10014500 : Integer) BinaryOutput : Text;

       BEGIN

         BEGIN

                 WHILE Value >= 1 DO BEGIN

                     BinaryOutput := FORMAT(Value MOD 2) + BinaryOutput;

                     Value := Value DIV 2;

                 END;

             END;

       END;

       LOCAL PROCEDURE BinaryToInt@10014521(Value@10014500 : Text) IntegerOutput : Integer;

       VAR

         Multiplier@10014501 : BigInteger;

         IntValue@10014502 : Integer;

         i@10014503 : Integer;

       BEGIN

         BEGIN

         Multiplier := 1;

                 FOR i := STRLEN(Value) DOWNTO 1 DO BEGIN

                     EVALUATE(IntValue,COPYSTR(Value,i,1));

                     IntegerOutput += IntValue * Multiplier;

                     Multiplier *= 2;

                 END;

             END;

       END;

       LOCAL PROCEDURE IncreaseStringLength@10014524(Value@10014500 : Text;ToLength@10014501 : Integer) Output : Text;

       VAR

         ExtraLength@10014502 : Integer;

         ExtraText@10014503 : Text;

       BEGIN

         BEGIN

                 ExtraLength := ToLength - STRLEN(Value);

                 IF ExtraLength < 0 THEN

                     EXIT;

                 ExtraText := PADSTR(ExtraText,ExtraLength,'0');

                 Output := ExtraText + Value;

             END;

       END;

       LOCAL PROCEDURE GetBase64Char@10014526(Value@10014500 : Integer) : Text;

       VAR

         chars@10014501 : Text;

         i@10014502 : Integer;

       BEGIN

         BEGIN

         chars := Base64Chars;

                 EXIT(FORMAT(chars[Value + 1]));

             END;

       END;

       LOCAL PROCEDURE GetBase64Number@10014529(Value@10014500 : Text) : Integer;

       VAR

         chars@10014501 : Text;

       BEGIN

         BEGIN

         IF Value = '=' THEN

                     EXIT(0);

                 chars := Base64Chars;

                 EXIT(STRPOS(chars,Value) - 1);

             END;

       END;

       LOCAL PROCEDURE Base64Chars@10014532() : Text;

       BEGIN

         BEGIN

                 EXIT('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');

             END;

       END;

       BEGIN

       END.

     }

    }

  • Suggested answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at

    Hi, This may be a problem with LS Nav, because this is not a standard function of NAV, it is recommended to contact the partner to solve it together.

    https://www.lsretail.com/products/ls-nav

    Hope this helps as well.

    Thanks.

    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,353 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,808 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,371

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans