An interesting tip today. Over the last few months there has been a thread on the Partner Forum (GP Notes Lockdown) with the request to prevent changes to the existing text on the Record Notes feature of Microsoft Dynamics GP.
The functionality request has two parts:
- Prevent existing notes from being deleted.
- Prevent existing text in the notes from being changed, only additions are allowed.
MVP Sivakumar Venkataraman took on the challenge and set about answering the forum post with a progression of solutions he published on his blog.
- Support Debugging Tool Customization #1 – Notes Disabler
- Notes Disabler Enhancements
- Support Debugging Tool Customization #2 – Notes Disabler Enhancements
The final post used the Support Debugging Tool to create 3 non logging triggers for each of the 5 Notes forms to provide the functionality desired (15 triggers in total).
The customer started using this approach but then noticed that the code did not behave correctly when the text in the note field was long. The problem was the code below, which was used to compare the text in the window field (for the length of the text saved in the table) against the text saved in the table. The idea is to detect if existing text has been changed.
The problem is that the substring() function returns a string with a maximum of 255 characters. So even though the requested length was larger than 255, only 255 would be returned. This meant that once the text in the note had exceeded 255 characters, it would always fail the comparison.
The solution is to write some code to build up a local text variable to the desired size using substring() to grab sections of 255 characters at a time. The final substring() will be whatever size is needed to reach the total length desired.
You can see we used the min() function to get the length for the final section correct.
Note: Siva’s blog post has been updated to use this solution.
I hope this code is handy if you ever need to use substring() on a text field.
// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)