Label Search – Exact Match in Custom SSRS Reports
Ever wanted to search for an exact label using the Label search form without having to click the “…” in a property window? If not, then you probably haven’t worked with custom SSRS reports too often.
As with all UI pieces, it is recommended that you use labels for all static text, especially for column labels. When working with SSRS reports, you have to use the Label editor from the tools menu in AX. When opened in this manner, the label editor will search for close matches, often returning many labels that are not useful. To get around this, we’ll make a small change to the SysLabelSearch form.
To start, create a new group under Group1 (Group1 holds the SearchString StringEdit). For the newly created group, called SearchGroup in this example; set the Width property to Column width, and set the Columns property to 2. Drag the SearchString StringEdit from Group1 into SearchGroup. Now, add a checkbox to SearchGroup, and name it cbExactMatch. Set the AutoDeclaration property on the cbExactMatch checkbox to Yes, the Label property to “Exact match”, and the DataMethod property to “exactMatch” (this method will be created shortly).
Open the code to the form, and add a NoYesId variable named exactMatch to the classDeclaration:
NoYesId exactMatch; // Kyle - Find exact match
Create a new edit method named exactMatch with a return type of NoYesId. The method will set the exactMatch variable added to the classDeclaration:
// Kyle - Find exact match
edit NoYesId exactMatch(boolean _set, NoYesId _value)
exactMatch = _value;
Change the method declaration of the labelSearch method to use the exactMatch variable as the optional parameter setter for the _findExactPhrase parameter:
public void labelSearch(str _text = searchString.text(), boolean _findExactPhrase = exactMatch) // Kyle - Find exact match
Modify the pack method to include the exactMatch variable (so that the lastValue is saved for the checkbox):
public container pack()
exactMatch]; // Kyle - Find exact match
Likewise, modify the unpack method to accept the exactMatch from lastValue. Replace line 21 with the following:
// Kyle - Find exact match -->
if (conLen(packed) == 8) // For people who have old last values
[version, languageId, notUsed_1, notUsed_2, autoSearchValue, notUsed_3, labelModuleId, languagePack] = packed;
[version, languageId, notUsed_1, notUsed_2, autoSearchValue, notUsed_3, labelModuleId, languagePack, exactMatch] = packed;
// Kyle - Find exact match <--
The above code ensures that a user won’t get an error when the form is first opened after the modifications. At all times after, the else block will be used.
When you open the form, you should see the new Exact match checkbox (it’ll be unchecked by default the first time the form is opened by each user). Search for Item Number with Exact match unchecked:
In my DEV environment, the search returned 275 results over 45 seconds. Additionally, I now have to search within the results to find the exact label.
Now, clear the search. Search again for Item Number, this time, checking the Exact match checkbox:
This time, the search returned only 9 results, all of which are an exact match for the phrase we typed in the search box. It also took only one second to return all results.
Hopefully, this simple example helps some of you in your UI design activities.
Kyle Self, Sr. Technical Consultant, AKA Enterprise Solutions