Thursday, August 7, 2008

Export a Document to Excel in Axapta using X++

static void MouliExcel(Args _args)
{
EmplTable EmplTableLocal;
SysExcelApplication excelApp;
SysExcelWorkSheet excelWorksheet;
SysExcelRange excelRange;
SysExcelCells excelCells;
SysExcelCell excelCell;
ComVariant cellValue;
Int i=1;
;
excelApp = SysExcelApplication::construct();
cellValue = new ComVariant() ;
excelApp.workbooks().add();
excelWorksheet = excelApp.worksheets().itemFromNum( 1 );
excelCells = excelWorksheet.cells();
while select * from EmplTableLocal
{
excelCells.item(i+4,4).value(cellValue.bStr(EmplTableLocal.EmplId));
excelCells.item(i+4,5).value(cellValue.bStr(EmplTableLocal.Name));
i++;
}
excelApp.visible(true);
//excelApp.quit();
}

export a document to MS Word from axapta using X++

COM wordApplication;
COM wordDocuments;
COM wordDocument;
COM wordRange;
;
wordApplication = new COM("word.application");
wordApplication.visible(TRUE);
wordDocuments = wordApplication.Documents();
wordDocument = wordDocuments.add();
wordDocument.saveas("c:\\YourDocument.doc");
wordDocument.activate();
wordRange = wordDocument.range(0,0);
wordRange.insertafter("mouli);
wordRange = wordDocument.range(6,19);

wordRange = wordDocument.range(11,26);
wordRange.italic(true);
wordDocument.save();
wordDocument.close();
wordApplication.quit();

sending Emails using X++ Code in Axapta

ysMailer mailer = new SysMailer();
SysEmailParameters parameters = SysEmailParameters::find();
mailer.fromAddress('moulikaku@hotmail.com');
mailer.fromName('minnu@gmail.com');
mailer.subject('What are you doing tonite???');
if (parameters.DNSServerName)
{
mailer.DNSServers().add(parameters.DNSServerName,
parameters.DNSTCPIPRetryCount,
parameters.DNSUDPRetryCount);
}

if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServers().add(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPServerIPAddress,
parameters.SMTPUserName,
parameters.SMTPPassword);

}
// Add your own code here, then send the message

======================================================

SysMailer mailer = new SysMailer();
mailer.body("My Body :)");
mailer.subject("WOW Baby");
mailer.fromAddress("minnu@anderson.com");
mailer.fromName("Peter Villadsen");
mailer.tos().add("moulikaku@gmail.com");
mailer.SMTPRelayServers().add("MyRelayServer");
mailer.sendMail();

======================================================
SysINetMail Mail=new SysINetMail() ;
Mail.sendMailAttach("minnu@gmail.com",
"mouli@gmail.com,
"WOW",
"My Body Text ;-)",
false,
"Attachment Path");


All the Best :-)
Publish Post
mouli

adding image by x++

Image image = new Image();
image.loadImage(_filePath);
. = image.getData();

Upgrade from AX 3.0 , AX4.0 to AX 2009

The steps below provide a high-level overview of the tasks that you must complete to upgrade from Microsoft Dynamics AX 3.0 to Microsoft Dynamics AX 2009.

•Back up your existing database and application files.

•Import two .xpo files from the installation media to assist with data upgrade.

• UpgradeColumnList.xpo, for 32-bit to 64-bit RecId field conversion.

• LeftJustified.xpo, for removing any trailing spaces from fields.

* Note: To help improve performance, you can apply the LeftJustified.xpo on the database that you create in step 4 after you’ve used the Microsoft Dynamics AX DB Upgrade Preparation tool but before you start the Microsoft Dynamics AX 2009 AOS.

•(Optional) To help improve performance, remove all user data and logs of Microsoft Dynamics AX 3.0. For example, clean up the SysDatabaseLog table.

•Create an empty database for Microsoft Dynamics AX 2009 in SQL Server 2005.

•(Optional) To help improve performance, set initial data and log file sizes so that they don’t increase while you perform the data upgrade process.

•(Optional) To help improve performance, set the recovery model to Simple for the Microsoft Dynamics AX 2009 Database.

•Run AXDBUpgrade.exe (The Microsoft Dynamics AX DB Upgrade Preparation tool). Note: To help improve performance, you can run this tool in Multithreaded mode. For example, to run this tool in 10 threads, enter AxDbUpgrade.exe P/10 at a command prompt.

•(Optional) Apply the LeftJustify file imported in step 2 to the Microsoft Dynamics AX 2009 database created in step 4.

•Back up your Microsoft Dynamics AX database. Your database is ready to be upgraded. •Run the Microsoft Dynamics AX 2009 Setup file from the installation media. During installation, select the database that you created in step 4.

•Copy your upgraded customized file into the correct application directory.

•Start the AOS.

•Start the Microsoft Dynamics AX 2009 client. The Upgrade checklist is displayed automatically.

•Complete the steps in the Upgrade checklist to finish upgrading.


The steps below provide a high-level overview of the tasks that you must complete to upgrade from Microsoft Dynamics AX 4.0 to Microsoft Dynamics AX 2009.


- Back up your existing database and application files. - (Optional) To help improve performance, remove all user data and logs of Microsoft Dynamics AX 4.0. For example, clean up the SysDatabaseLog table.

- (Optional) To help improve performance, set initial data and log file sizes so that they don’t increase while you perform the data upgrade process.

- (Optional) To help improve performance, set the recovery model to Simple for the Microsoft Dynamics AX 2009 Database. - Back up your Microsoft Dynamics AX database. Your database is ready to be upgraded.

- Run the Microsoft Dynamics AX 2009 Setup file from the installation media. During installation, select your existing Microsoft Dynamics AX database.

- Start the Microsoft Dynamics AX 2009 client. The Upgrade checklist is displayed automatically.

- Complete the steps in the Upgrade checklist to finish upgrading.

Upgrading to Microsoft Dynamics AX 4.0 and Microsoft Dynamics AX 2009 -convergence session please check following link Click Here

How to call Axapta methods from .net

Using .NET Business Connector, you can access Microsoft Dynamics AX data or business logic from a .NET-connected application.
To add a reference to .NET Business Connector
•Open Visual Studio.
•In Solution Explorer, right-click References and select Add Reference.
•In the Add Reference window, select the Browse tab.
•Specify the location of Microsoft.Dynamics.BusinessConnectorNet.dll, and then click Add.
Add code to call a Microsoft Dynamics AX method in Visual Studio C#.
using System;
using Microsoft.Axapta.BusinessConnector;
namespace AXMethodCall
{
class Class1
{
static void Main(string[] args)
{
// Create the .NET Business Connector objects.
Axapta ax;
object o;
bool b;
try
{
// Login to Microsoft Dynamics Ax.
ax = new Axapta();
ax.Logon(null, null, null, null);
}
catch (Exception e)
{
Console.WriteLine("An error occurred in object creation or Axapta logon: {0}", e.Message);
return;
}
// Logon was successful.
try
{
// Call a static class method.
o = ax.CallStaticClassMethod("Class Name ", "Method Name",Argument);
}
catch (Exception e)
{
Console.WriteLine("An error has been encountered during CallStaticClassMethod: {0}", e.Message);
b = ax.Logoff();
return;
}
// Log off from Microsoft Dynamics AX.
b = ax.Logoff();
}
}
}

Send Alert to user from code in AX 4.0

// To send Alert to User From Code
void sendAlertToUsers()
{
SysMailer mail;
UserInfo UserInfo;
EventInbox inbox;
EventInboxId inboxId;
;

select UserInfo where UserInfo.id == CurUserId();
inboxId = EventInbox::nextEventId();

inbox.initValue();
inbox.ShowPopup = NoYes::Yes; // To show Pop up
inbox.Subject = "Aleart Message Through Code";
inbox.Message = "Testing Alerts";
inbox.AlertedFor = "This alert is just for information(Testing)";
inbox.SendEmail = false;
inbox.UserId = UserInfo.Id;
inbox.TypeId = classnum(EventType);
//Enter Table and Field Details
inbox.AlertTableId = TableNum(EmplTable); // Table for which Alert is Generated
inbox.AlertFieldId = fieldNum(Empltable ,Name); // Field for which Alert is Generated
inbox.TypeTrigger = EventTypeTrigger::FieldChanged;
inbox.CompanyId = CurExt();
inbox.InboxId = inboxId;
inbox.AlertCreatedDate = systemdateget();
inbox.AlertCreateTime = timeNow();
inbox.insert();
}

import/export of chart of accounts by using X++ in microsoft Dynamics Axapta

Almost regularly I receive emails requesting for import/export jobs. Here are couple of simple examples. If you have any query, please do not hesitate to contact me..

1) Here is a small job that imports Chart of Accounts into Axapta. Please note that this job is meant more as a starting point for beginners in Axapta. Considering that, I have added some comments across the job.
------------------------------------------------------------------------
static void CoAImport(Args _args)
{

/*
*************************************************************************

Author : mouliyadav

Purpose : Demonstration for importing CoA into Axapta

*************************************************************************
*/

LedgerTable ldt;
AsciiIO inFile;
Filename filename;
Container line;
Dialog dialog;
DialogField dialogField;
;

/*
Note - In this example, I have used 'Dialog' & DialogField classes
as a tool for me to select the file that has to be imported. If required, you can directly select
the file to be imported. For ex -
filename = 'C:\\';
*/

dialog = new Dialog("Import Chart of Accounts");
dialogfield = dialog.addField(typeid(Filenameopen), "File Name");
dialog.run();

if (dialog.run())
{
filename = (dialogfield.value());
}

/*
Note - In this example, I have used AsciiIO class. But you can also use
CommaIO class as well. Basically all these classes (AsciiIO, CommaIO,
Comma7Io etc) derives from 'Io' base class. For more info, please
refer to Io class.
*/
inFile = new AsciiIO (filename, 'R');

if (!inFile || infile.status() != IO_Status::Ok )
{
//strfmt - function for formatting text string
throw error (strfmt("@SYS19312",filename));
}
ttsbegin;

infile.inRecordDelimiter('\n');
infile.inFieldDelimiter(',');

//Checking status of last operation..
while (infile.status() == IO_status::Ok)
{
line = infile.read();

if (line)
{
ldt.initValue();
ldt.AccountNum = conpeek(line,1);
ldt.AccountName = conpeek(line,2);
ldt.AccountNameAlias = conpeek(line,3);
ldt.AccountPlType = conpeek(line,4);
ldt.doInsert();
}
}
ttscommit;

/*
Some additional notes:

1) 'line' is a container. It is a general data type. Its purpose is very similar to temporary tables.
However there are some subtle yet great difference between temp tables and containers. For more info,
please refer to Developer's guide.

2) Conpeek - To return specific element from a container
*/
}
------------------------------------------------------------------------


2) I wrote this simple job to demonstrate exporting data from Axapta. Also I have mentioned few file operations like copying into clipboard, deletion etc. Please note that I have used CommaIO class here. If required it is also possible to use class like AsciiIO etc. Here I go ....
static void FileOperations(Args _args)
{
/*
......................................................

Author : Harish Mohanbabu

Purpose : Demonstration for creating a text file and
writing contents into that file
......................................................
*/

CustTable cust;
CommaIO myfile;
TextBuffer tb;
counter recordCount;
int i;
str fileName;
;

fileName = "C:\\Axapta1.txt"; //<- Alternatively 'Dialog' can be used.
//<- Instead of '.Txt', extensions like
//.Doc, .Xls can also be used.

//Creating new file with write access
myfile = new commaIO(fileName,"w");


//Setting up Record delimiter
myfile.outRecordDelimiter("\r\n");
myfile.outFieldDelimiter(",");


while select cust order by accountnum
{
myfile.write(cust.AccountNum, cust.Name);
}

myfile.write('..........................................');


//To find out record count & write the same end of the file
recordcount = new sysdicttable(tablenum(custTable)).recordCount();
myfile.write("Inserted " + int2str(recordcount) + " Records");


//To close this file
myfile = null; //<- Finalize() method is protected. Hence this alternative ...


//To copy contents of this file into clipboard
tb = new TextBuffer();
tb.fromFile(filename);
tb.toClipboard();
tb = null;


//To delete this file
//winapi::deleteFile(fileName);


//Alternatively To move this file
//winapi::moveFile(fileName, newfileName); // <- Declare 'newfileName'
}


3) I wrote this simple job to demonstrate connecting to a website from Axapta and downloading a web page into the local hard disk. Here I go ....
static void ReadHTML(Args _args)
{
......................................................

Author : Harish Mohanbabu

Purpose : Demonstration for connecting to a website and
downloading a webpage from there....
......................................................

str page;
str filename;
commaIO myfile;
int handle;
WinInet wi = new WinInet();
;

filename = "C:\\HTMLfile.txt";
myfile = new commaIO(filename,"w");
handle = wi.internetOpenUrl('http://www.axaptabangalore.blogspot.com');

if (handle)
{
page = wi.internetReadFile(handle);
myfile.write(page);
}

wi.internetCloseHandle(handle);

}

To Open An External File by using X++ in axapta

hi,
try this
static void OpenFile(Args _args)
{
;
WinAPI::shellExecut e('filePath');
}

Benifits of Axapta

enefits of Microsoft Dynamics Axapta India

Microsoft Axapta is a Business Management enterprise resource planning (ERP) solution created specifically to help medium-sized businesses quickly seize opportunity and improve their competitive advantage. It is Easy to implement, customize, and modify Business software. With multicurrency and Multilanguage features, Axapta supports companies in various countries including India.

Microsoft Dynamics AX brings people, processes, and information together wherever they are located around the globe, to increase the productivity and effectiveness of your business and help employees drive business success. In addition, Axapta India offers new capabilities and enhancements across the manufacturing, distribution and financial applications.

Microsoft Axapta is useful for many businesses in:

1. Axapta Enterprise Portal  Framework used to build personalized websites

2. The product builds on previous Internet connectivity with expanded roles and functionality.

3. Secure Connectivity: Businesses using Axapta can now securely connect relevant stakeholders  including partners, customers and employees  directly to Axapta, including those who previously worked offline and outside the system.

4. Business Reporting at its Best: Reports and catalogs can be viewed with the ability to register project hours, participate in discussion forums, and publish and exchange documents such as electronic drawings.

5. Multiple language and currency capabilities also enable businesses to work in the language and currency of their choice.

6. Release 3.0 also builds on the deep manufacturing functionality in Axapta with new intercompany collaboration and inventory management capabilities. Subsidiaries or distribution centers can trade internally and rely on an accurate overview of stock availability throughout the business.

7. Warehouse management also is easier with improved inventory dimensions, tracking system and bar code functionality.

Axapta KEY BENEFITS:

" Provide a fast, easy way to set up alerts. People can right-click within any Microsoft Dynamics AX record to define an alert rule for changes and events that they want to monitor.

" Work more pro actively by specifying which events to monitor. Maintain tighter control over business activity by defining conditions for alert rulesfor example, set up an alert rule to notify you one day before a shipment from a certain vendor is due.

" Meet specific needs for your business. Tailor alerts to your business priorities by creating templates for alert rules or modifying existing rules for individual users.

" Provide flexible delivery options. Help ensure people get the information they needas pop-up windows, e-mail messages through Microsoft Office Outlook?, or through Enterprise Portal for Microsoft Dynamics AXall right from within Microsoft Dynamics AX.

" Helps you ensure regulatory compliance and expand your business across geographies

" Helps you improve the efficiency of your financial operations and enable strategic planning

" Helps you manage your cash flow effectively

" Provides greater insight into your finances and improves your ability to make the right decisions quickly


GT Kimberly is an ardent follower of IT Software News. He is a regular reader of news happenings of Big Companies like Microsoft, Google etc... GT Kimberly is an ardent follower of IT Software News. He is a regular reader of news happenings of Big Companies like http://www.microsoft.com/india/dynamics/default.mspx">Microsoft http://news.google.com/news?hl=en&ned=us&q=IT+software&btnG=Search+News">Google etc...

http://www.microsoft.com/india/dynamics/product/dynamics_ax.mspx> Microsoft Dynamics AX