Friday, 15 August 2008

Spell Checker in Dynamics AX

Dynamics AX has a neat little SpellChecker class that can help in catching those spelling mistakes. This can be helpful when you are creating parser which needs to check words for correct spellings. It is very simple to use. Here is a sample job.

static void SpellChecker(Args _args)
{
Array array;
List list;
ListIterator listIterator;
SysSpellChecker sysSpellChecker;

int i;
;
array = new Array(Types::String);
array.value(1,"Hello");
array.value(2,"Werld");
sysSpellChecker = SysSpellChecker::newCurrentDocumentationLanguage();
for(i=1;i<=array.lastIndex();i++)
{
if(!sysSpellChecker.checkSpelling(array.value(i)))
{
list = SysSpellChecker::newLanguageId("en-us").getSpellingSuggestions(array.value(i));
listIterator=new ListIterator(list);
print "Spelling suggestions for '",array.value(i),"'";
while(listIterator.more())
{
print listIterator.value();
listIterator.next();
}
}
}
pause;
}

Friday, 15 June 2007

Task method on Form

Suppose you have a form with a grid control which displays some record.

Now through code, you want to move ahead or back in the grid, similar to like moving to next record or previous record. That can be done using the task method on the form.

The task method takes an int argument that defines the task to be performed. For moving to the next record, the task id is 2817 and moving to the previous record the task id is 2818.

Insert a button, name it Next and put the following code in the clicked method

void clicked()
{
super();
element.task(2817);
}

So when you click this button, the cursor will move to the next record in the grid. Some of the other tasks and their ids are given below.

Tasks Task Ids
=======================
New 260
Save 272
Print 278
PrintPreview 299
Cut 770
Copy 771
Paste 772
Find 779

NextRecord 2817
PreviousRecord 2818
FirstRecord 2823
LastRecord 2824
Delete 2832

Wednesday, 30 May 2007

Add menu items to the context menu in Dynamics

You can add your own menu items to the Context menu in Dynamics by adding a reference of the menu item to the SysContextMenu menu.

As seen in the image, I have added a class menu item ShowFormMethods to the sysContextMenu. After I save, I right click on any node in AOT and goto Add-ins, I can see my menu item.

You can also add a menu item to Tools -> Development Tools by adding a reference of the menu item to DevelopmentTools menu.

I have added a small project which you can look into and see how it has been done. Download it
here.





Friday, 25 May 2007

Handling events of runtime form controls

Sometimes you may have to create a form during run time. That can be easily done by creating an object of the Form class. You can also create objects of different controls and add. But what if you want to handle events of these controls?

For this you have to tell the form system where to look for events. This can be done by calling the controlMethodOverload on the formRun with a true value. This makes the form look for methods on the formRun object. But we cannot add methods on the formRun object because it is created during runtime. So you can tell the form which object to look for the methods by providing the object to the controlMethodOverloadObject method.

Method’s name must have the following naming convention and it must be strictly followed, _ ex, MyButton_clicked

1. Create a class like given below,

class RunTimeFormClass
{
}

2. Add a method createForm to it like this

void createForm()
{
FormBuildDesign formBuildDesign;
FormButtonControl myButton;
FormRun formRun;
Form form;
Args args;
;
form=new Form();

formBuildDesign=new FormBuildDesign();
formBuildDesign=form.addDesign("Design");

myButton=formBuildDesign.addControl(FormControlType::Button,"myButton");
myButton.text("Click Me!");

args=new Args();
args.object(form);

formRun=new FormRun(args);
formRun.controlMethodOverload(true);
formRun.controlMethodOverloadObject(this);
formRun.init();
formRun.run();
formRun.detach();
}

3. Create another method myButton_clicked like this,

static void myButton_clicked()
{
;
Box::info("Button Clicked");
}

4. Now create a job and insert the following code,

static void createForm(Args _args)
{
RunTimeFormClass obj=new RunTimeFormClass();
obj.createForm();
}

That’s all, when you run the job you can see a form with a button, click the button and you will get a Box with “Button Clicked” message.

Export data of selected tables only...

Sometimes when you want to share data in your tables with other, you export it from Administration -> Periodic -> Data export/import -> Export to. But this exports data in all your tables. What if you want to export data from selected tables only? Here is how you can do that.

First create a definition group from Administration -> Periodic -> Data export/import -> Definitions group
In the definition group form, create a new group. Name it XYZ.
Click on Table setup button.
By default, the table setup form has all the tables listed, select and delete all of them.
Now add only the tables you want data to be exported for.
Now click on Administration -> Periodic -> Data export/import -> Export to
In the definition group, specify the group we created above and click OK

In this way, you can export data for selected tables only.