Recently I got a requirement to increase the length of the comment field (for example in Customers, Vendors, Sales Documents, Contacts etc) as in standard NAV the comments limit is 80 characters per line. We could increase this limit, but the issue is that the maximum length of a text field accepted by NAV is 250 charactes and they we’re looking at 500 characters plus- ideally more.
So, what I did is to add a new Assist Edit button to the Comment Line pages. When pressed, the system finds all comments added in the specific date (including lines with out date) and combines them into one TextBox on to a separate page. For a new comment line, the system creates new entries. Users are able to change the existing comment in the new page and when the OK button is clicked, the system splits the text value into 80 char lines and inserts new lines with maximum 80 characters until the end of the big string (for example, for a string of 800 lines it will create 10 comment lines of 80 chars each). If any existing comment line is changed, the system deletes related existing comment lines and recreates the lines.
In a few images it looks like this:
- Open Customer 10000, select a new line to add a new comment (Navigate- Comments). Press Assist Edit:
- Add your Extended Comment:
- Press Ok to save the comment. The program automatically splits the Extended Comment into lines of maximum 80 characters:
- Edit again the comment:
- Open again and shorten the comment. I added also a comment from another date to prove the program affects only entries from the same date:
- Make a shorter comment for date 24/01/2019:
- The new lines are created again based on what users input in the Extended Comments page:
Coding:
In order to create this functionality:
Created 2 new Objects:
- Page: Extended Comment Display
SetDisplayTextSales(pSalesCommentLine : Record "Sales Comment Line") CASE TRUE OF STRLEN(pSalesCommentLine.Comment) > 0 : BEGIN CLEAR(ExtendedCommentText); SalesCommentLine.SETRANGE("Document Type", pSalesCommentLine."Document Type"); SalesCommentLine.SETRANGE("No.", pSalesCommentLine."No."); SalesCommentLine.SETRANGE("Document Line No.", pSalesCommentLine."Document Line No."); SalesCommentLine.SETFILTER(Date, '%1|%2', pSalesCommentLine.Date, 0D); IF SalesCommentLine.FINDSET THEN REPEAT ExtendedCommentText += SalesCommentLine.Comment; UNTIL SalesCommentLine.NEXT = 0; END; END; CommentView := SalesCommentLine.GETVIEW; InitialExtendedCommentText := ExtendedCommentText; SetDisplayTextContact(pRlshpMgtCommentLine : Record "Rlshp. Mgt. Comment Line") CASE TRUE OF STRLEN(pRlshpMgtCommentLine.Comment) > 0 : BEGIN CLEAR(ExtendedCommentText); RlshpMgtCommentLine.SETRANGE("Table Name", pRlshpMgtCommentLine."Table Name"); RlshpMgtCommentLine.SETRANGE("No.",pRlshpMgtCommentLine."No."); RlshpMgtCommentLine.SETRANGE("Sub No.", pRlshpMgtCommentLine."Sub No."); RlshpMgtCommentLine.SETFILTER(Date, '%1|%2', pRlshpMgtCommentLine.Date, 0D); IF RlshpMgtCommentLine.FINDSET THEN REPEAT ExtendedCommentText += RlshpMgtCommentLine.Comment; UNTIL RlshpMgtCommentLine.NEXT = 0; END; END; CommentView := RlshpMgtCommentLine.GETVIEW; InitialExtendedCommentText := ExtendedCommentText; SetDisplayTextCommentLine(pCommentLine : Record "Comment Line") CASE TRUE OF STRLEN(pCommentLine.Comment) > 0 : BEGIN CLEAR(ExtendedCommentText); CommentLine.SETRANGE("Table Name", pCommentLine."Table Name"); CommentLine.SETRANGE("No.", pCommentLine."No."); CommentLine.SETFILTER(Date, '%1|%2', pCommentLine.Date, 0D); IF CommentLine.FINDSET THEN REPEAT ExtendedCommentText += CommentLine.Comment; UNTIL CommentLine.NEXT = 0; END; END; CommentView := CommentLine.GETVIEW; InitialExtendedCommentText := ExtendedCommentText; GetDisplayText() : Text EXIT(ExtendedCommentText); CheckExtendedCommentIsModified() : Boolean EXIT(ExtendedCommentText <> InitialExtendedCommentText); GetCommentView() : Text EXIT(CommentView); SetCommentDate(pCommentDate : Date) CommentDate := pCommentDate;
- Codeunit: Extended Comments Mgt.
RecreateCommentLineComments(CommentLineView : Text;NewExtendedComment : Text) CommentLine.SETVIEW(CommentLineView); //copy info to temporary table IF NOT CopyOldCommentLineDetails(TempCommentLine, CommentLine) THEN EXIT; //delete existing lines CommentLine.DELETEALL; //reinsert lines InsertCommentLines(NewExtendedComment, TempCommentLine, FALSE); LOCAL CopyOldCommentLineDetails(VAR CommentLineTemp : TEMPORARY Record "Comment Line";VAR CommentLine : Record "Comment Line") : Boolean IF CommentLine.FINDFIRST THEN BEGIN CommentLineTemp := CommentLine; CommentLineTemp.INSERT; EXIT(TRUE); END; EXIT(FALSE); InsertCommentLines(NewExtendedComment : Text;VAR TempCommentLine : TEMPORARY Record "Comment Line";FromEmptyLine : Boolean) NewCommentLenght := STRLEN(NewExtendedComment); i := 1; WHILE i < NewCommentLenght DO BEGIN CommentLine.TRANSFERFIELDS(TempCommentLine); IF FromEmptyLine THEN CommentLine."Line No." := FindLastUnusedLineNoCommentLine(TempCommentLine) ELSE CommentLine."Line No." := FindFirstUnusedLineNoCommentLine(TempCommentLine); CommentLine.Comment := COPYSTR(NewExtendedComment, i, MAXSTRLEN(CommentLine.Comment)); CommentLine.INSERT; i += MAXSTRLEN(CommentLine.Comment); END; LOCAL FindFirstUnusedLineNoCommentLine(TempCommentLine : TEMPORARY Record "Comment Line") : Integer LineNo := 10000; WHILE CommentLine.GET(TempCommentLine."Table Name", TempCommentLine."No.", LineNo) DO LineNo += 10000; EXIT(LineNo); LOCAL FindLastUnusedLineNoCommentLine(TempCommentLine : TEMPORARY Record "Comment Line") : Integer CommentLine.SETRANGE("Table Name", TempCommentLine."Table Name"); CommentLine.SETRANGE("No.", TempCommentLine."No."); IF CommentLine.FINDLAST THEN EXIT(CommentLine."Line No." + 10000) ELSE EXIT(10000);
Added code in the Standard Nav Comment Line pages:
- ex: Comment Sheet
Comment - OnAssistEdit() // <<AL>> ExtendedCommentDisplay.SetDisplayTextCommentLine(Rec); ExtendedCommentDisplay.SetCommentDate(GetDisplayDate); ExtendedCommentDisplay.LOOKUPMODE(TRUE); IF ExtendedCommentDisplay.RUNMODAL = ACTION::LookupOK THEN IF ExtendedCommentDisplay.CheckExtendedCommentIsModified THEN BEGIN NewExtendedComment := ExtendedCommentDisplay.GetDisplayText; IF STRLEN(Comment) > 0 THEN ExtendedCommentsMgt.RecreateCommentLineComments(ExtendedCommentDisplay.GetCommentView, NewExtendedComment) ELSE BEGIN CreateTempCommentLine(TempCommentLine, Rec); ExtendedCommentsMgt.InsertCommentLines(NewExtendedComment, TempCommentLine, TRUE); END; END; CurrPage.UPDATE(FALSE); ----- LOCAL CreateTempCommentLine(VAR TempCommentLine : TEMPORARY Record "Comment Line";CommentLine : Record "Comment Line") // <<AL>> TempCommentLine.INIT; TempCommentLine.TRANSFERFIELDS(CommentLine); IF TempCommentLine.Date = 0D THEN TempCommentLine.Date := WORKDATE; TempCommentLine.INSERT; LOCAL GetDisplayDate() : Date // <<AL>> IF Date = 0D THEN EXIT(WORKDATE) ELSE EXIT(Date);
This is part of the code written, if you would like to try the functionality you can download the files from THIS DOWNLOAD LINK.
*please note that at this moment it is developed for Customers and Vendors, Sales Documents and Contacts. If you want to use it also for other areas you will need to change it. I am thinking of a more generic way of doing this (using RecRefs instead of copying and editing code for all Comment tables)