AX Spell Checker Suggestion
“SysSpellChecker” as the name suggest checks the spelling mistake and provides you with the list of spellings that may be useful or applicable.
Sample job is illustrated using SysSpellChecker class. AX spell checker class is integrated with Word where methods like below are provided by COM classes.
· activeSpellingDictionary
· Checkspelling
· getSpellingSuggestions
|
static void SysSpellChecker_AX(Args _args) { SysSpellChecker sysSpellChecker; container spellings; ListEnumerator listEnumerator; List spellingsSuggestions; int i; ;
spellings = ['Tble', 'Comput', 'Mcrosft', 'Rlease'];
// Get AX –> Current Language id // Construct the sysSpellChecker object. sysSpellChecker = SysSpellChecker::newCurrentDocumentationLanguage();
startLengthyOperation();
for(i=1; i<= conlen(spellings); i++) { if(! sysSpellChecker.checkSpelling(conpeek(spellings, i))) { spellingsSuggestions = sysSpellChecker.getSpellingSuggestions(conpeek(spellings, i)); listEnumerator = spellingsSuggestions.getEnumerator();
while(listEnumerator.moveNext()) { print "Suggested Spellings are:" + listEnumerator.current(); pause; } } } sysSpellChecker.finalize();
print "Your done with Spell check."; pause;
endLengthyOperation(); } |

Above example is shown using AX class. But using COM class we can still get the suggested spellings if it’s incorrect.
|
static void SpellChecker_COM_Word(Args _args) { System.Globalization.CultureInfo cultureInfo;
COM wordDocs; COM languages, language; COM dictionaries; COM word; COM languageDictionary; COM customDictionary; COM suggestionsObj; COM suggestion;
List suggestions = new List(Types::String); ListEnumerator listEnumerator;
int lines = infolog.line(); int languageId; int i;
Session session = new Session(sessionid()) ;
void initDictionary(LanguageId _language) { Set dictionary; ;
dictionary = new Set(Types::String);
dictionary.add(‘Axapta’); dictionary.add(‘MorphX’); dictionary.add(‘Microsoft Dynamics AX’); dictionary.add(‘Damgaard’); dictionary.add(‘nbsp’); //HTML nonbreakable space
if (_language == ‘En-Us’) { //Often used words added to speed up checking dictionary.add(‘is’); dictionary.add(‘isn’); dictionary.add(‘has’); dictionary.add(‘hasn’); dictionary.add(‘was’); dictionary.add(‘wasn’); dictionary.add(‘then’); dictionary.add(‘a’); dictionary.add(‘in’); dictionary.add(‘the’); dictionary.add(‘this’); dictionary.add(‘not’); dictionary.add(‘can’); } }
cultureInfo = new System.Globalization.CultureInfo(session.interfaceLanguage()); languageId = cultureInfo.get_LCID();
if (!word) { try { word = new COM(‘Word.Application’); } catch (Exception::Internal) { infolog.clear(lines); throw error("@SYS74320"); } }
//Need to add a document or else Word97 will fail //the calls to Application.GetSpellingSuggestions wordDocs = word.documents(); wordDocs.add(); word.windowState(0); initDictionary(session.interfaceLanguage());
try { languages = word.languages(); language = languages.item(languageId); languageDictionary = language.activeSpellingDictionary(); dictionaries = word.customDictionaries(); customDictionary = dictionaries.activeCustomDictionary();
suggestionsObj = word.getSpellingSuggestions(‘Speling’, customDictionary, languageDictionary); for (i=1; i<=suggestionsObj.count(); i++) { word.checkspelling(‘Speling’, customDictionary, true, languageDictionary); suggestion = suggestionsObj.item(i); suggestions.addEnd(suggestion.name()); }
listEnumerator = suggestions.getEnumerator(); while(listEnumerator.moveNext()) { print "Suggested Spellings are:" + listEnumerator.current(); pause; }
word.quit(); } catch (Exception::Internal) { infolog.clear(lines); throw error(strfmt("@SYS84011", session.interfaceLanguage())); } } |
Download Link:http://cid-264a0056cbcbb1d3.skydrive.live.com/self.aspx/.Public/Job%5E_SpellChecker.zip
Happy Spell check
dAXing.
Mm…thx anna…As usual i\’m always becoming active blogger by seeing you[:)]
Good one Santhu…Simply Superb
Hey tanky!!! Anitu….You ppl are constantly encouraging me so i cum up with such small and useful stuffs in AX
As always .. informative..
Awesum !!!