Wednesday, September 3, 2008

Problem when creating a dynamic form with ActiveX control & Solution :)

The Requirement was to connect to the web and get the content of the web page and display it on

the form .Well, I did not want to create a form in AOT to display the HTML content .So , I thought of dynamically creating a form and adding the browser ActiveX Control using X++ code.

Here is the code which I pasted in the job.

static void ActiveX_DynamicForm(Args _args)

{

COMDispFunction webpreviewWrite;

COMVariant text = new COMVariant();

COM ctrl = new COM();

Form formBrowse;

FormActivexControl activex;

FormRun formRun;

Args args;

int handle;

WinInet wi = new WinInet();

str htmlContent;

;

handle = wi.internetOpenUrl('http://www.yahoo.com');

if (handle)

{

htmlContent = wi.internetReadFile(handle);

}



wi.internetCloseHandle(handle);

formBrowse = new Form('ActiveX AX Form', true);

formBrowse.design().width(500);

formBrowse.design().height(500);

formBrowse.design().addControl(FormControlType::ActiveX, 'Browser');

args = new Args(formBrowse.name());

args.name(formBrowse.name());

args.object(formBrowse);

formRun = classFactory.formRunClass(args);

formRun.init();

activex = formRun.design().controlName('Browser');

activex.className('{8856F961-340A-11D0-A96B-00C04FD705A2}');

activex.height(1,1);

activex.width(1,1);

formRun.run();

ctrl.attach(activex.interface());

webpreviewWrite = new COMDispFunction(ctrl, 'write', COMDispContext::Method);

text.bStr(htmlContent);

activex.open("");

webpreviewWrite.call(text);

formRun.detach();

}

I was successful in creating the form but strangely AX threw me an error when I ran the code. It was not supporting ‘write’ method for automatic interface of COM object of class “IWEBBrowser2’

I did not want to create a separate form adding an ActiveX control to achieve this.

I looked for alternatives and found one interesting class which served my purpose.

Class Name: KMKnowledgeFunctionShow

Method : static Object show(TextBuffer htmlText, Object _formRun = null)

The show method will open the standard “KMKnowledgeAnalogMeter” form which has an ActiveX Control added to it.

I got the content of the webpage and added it to the TextBuffer by using settext() method and passed the TextBuffer to the show method. I did not pass the second parameter formrun.

The idea behind this is to open the existing Standard form which has already Browser ActiveX in it.

Here is the code

static void ActiveX_Alternate(Args _args)

{

str htmlContent;

TextBuffer txtBuffer;

int handle;

WinInet wi = new WinInet();

;

handle = wi.internetOpenUrl('http://www.yahoo.com/');

if (handle)

{

htmlContent = wi.internetReadFile(handle);

}

txtBuffer = new TextBuffer();

txtBuffer.setText(htmlContent);

KMKnowledgeFunctionShow::show(txtBuffer);

}

Drawback: The form caption stills remains the “KMKnowledgeAnalogMeter “form caption

Create Outlook Appointment or Meeting Request using X++

If you need to create an appointment or meeting request in Outlook using X++, just borrow the code below. Outlook client needs to be installed on the machine where the code is run.

Here is the job.

static void OutlookAppointment(Args _args)

{

COM sysOutlookCollection;

COM collection;

COMVariant comStartDate = new COMVariant();

COMVariant comEndDate = new COMVariant();

COM c;

#SysOutLookCOMDEF

#define.mapi("MAPI")

#define.outlook("Outlook.Application")

COM sysOutlook;

COM sysOutlookNameSpace;

COM sysOutlookMAPIFolder;

;

sysOutlook = new COM(#outlook);

sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);

sysOutlookNameSpace.logon();

sysOutlookMAPIFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderCalendar);

collection = sysOutlookMAPIFolder.items();

c = collection.add();

comStartDate.date(today());

comStartDate.time(str2Time( "12:00:00"));

comEndDate.date(today());

comEndDate.time(str2Time( "12:45:00"));

c.location('Solugenix 4th Floor Conference Room, India');

c.subject('Meeting regd Microsoft Dynamics AX 2009');

c.body('Lets discuss on whats new in DAX 2009');

c.start(comStartDate);

c.end(comEndDate);

c.save();

if (c)

{

c.display();

info("The action is created in Microsoft Outlook");

}

else

throw error("@SYS31969");

sysOutlookNameSpace.logoff();

}

Get the Exchange Rates for the given Currency using X++

I did MSN search and found a public web service; webservicex.net that provides a public currency converter web service.
This code snippet accesses a public web service to get the exchange rate for a given currency using x++.

static void GetExchangeRates(Args _args)

{

com com = new com('microsoft.xmlhttp');

com com1;

XMLDocument xmlDoc;

Dialog exchDialog = new Dialog("Exchange Rates");

DialogField fromField;

DialogField ToField;

str url;

;

fromField = exchDialog.addField(Types::String, 'Base Currency');

fromField.value(CompanyInfo::find().CurrencyCode);

ToField = exchDialog.addField(Types::String, 'To Currency');

if(exchDialog.run())

{

url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?";

url += "FromCurrency=" +strupr(fromField.value())+"&ToCurrency="+strupr(ToField.value());
com.open("get",url, false);

com.send();

com1 = com.responsexml();

xmlDoc = XmlDocument::newXml(com1.xml());

info("1 "+fromField.value() + " = " +xmlDoc.getNamedElement('double').text() + " " +ToField.value());

}

}

Generate XML Documentation Files for a project - DAX 2009

To generate XML documentation files for a project

1.

Open the Projects form by pressing CTRL+SHIFT+P.
2.

Right-click the project for which you want to create XML documentation files, point to Add-Ins, and then click Extract XML documentation.
3.

Select the Documentation check box if you want to create a documentation file for the project.The documentation file contains the documentation from the header templates in the source code
4.

Select the Reflection check box if you want to create a reflection file for the project.The reflection file contains reflection information about all the classes, tables, methods, data types, and base enumerations in the current layer
5.

In the File name fields, specify the destination of each file.

You can generate these XML files for a project or for the entire application. XML files for a project are generated by using a command in Microsoft Dynamics AX. XML files for the entire project are generated by using the command prompt. Generating XML files for the entire application can take a long time, depending on how much documentation has been written in the code

To generate XML documentation files for the entire application
Create a folder in which you will create the XML documentation files. This procedure will reference a folder that has the path, C:\XMLDoc.

Note: For security purposes, you may not be able to create XML documentation files directly on the root of a drive.

At the command prompt, execute the following command to create a documentation file for the entire application: Ax32.exe -startupcmd=xmldocumentation_C:\XMLDoc\documentation.xml

At the command prompt, execute the following command to create a reflection file for the entire application:
Ax32.exe -startupcmd=xmlreflection_C:\XMLDoc\reflection.xml

Note :When you use these commands, Microsoft Dynamics AX will automatically start and create the XML files. Microsoft Dynamics AX will automatically close when it finishes.

Friday, August 29, 2008

Welcome to AX Devolopers

Welcome to AX Devolopers