Skip to main content

Posts

Showing posts from October, 2012

Microsoft Dynamics AX 2012 Source to Target data upgrade

What is this feature ? The source to target upgrade model provides a framework to reduce the downtime for AX upgrade.The upgrade downtime is achieved by enabling upgrade on both the source AX system (Ax 4.0 or AX 2009) and target AX system (Ax 2012). The upgrade consists of following steps. 1. Pre-upgrade processing on a live source AX system 2. Bulk data copy to target system, 3. Optimized data transformations (write once per table), and sync-on-the-fly to the target AX 2012 4. Fix duplicate RecID as a part of the upgrade process How do we upgrade using this feature ? The user installs an XPO on the source AX system being upgraded, launches the pre-upgrade checklist, and walks through the pre-upgrade checklist items. Most of the checklist tasks can be executed on a live AX system and rest within a single user mode. Concurrently the user can setup the AX 2012 environment for upgrade by installing AX 2012, choosing the upgrade option, and then launching the upgrade checklist an...

How to update vendor addresses in Dynamics AX 2009

static void  UpdateVendAddressType(Args _args) { VendTable      vendTab; // Replace VendTable with CustTable when run this for  customers. DirPartyTable dirPartyTab; Address           addTab; ; ttsbegin; while select vendTab join dirPartyTab join forupdate addTab where vendTab.PartyId == dirPartyTab.PartyId && addTab.AddrTableId == dirPartyTab.TableId && addTab.AddrRecId == dirPartyTab.RecId {       if(addTab.Name == ‘Birincil Adres’)      {         addTab.type = AddressType::Payment;         addTab.update();      } } ttscommit; }

Merging Two records

//we will explore how to correct such a situation by merging two records including //all their related transactions. For the demonstration, we will merge two vendor accounts 5001 //and 5002 into a single one, that is, 5001. static void VendAccountMerge(Args _args) { VendTable vendTable; VendTable vendTableDelete; PurchJournalAutoSummary jourSummary; #define.vend('5001') #define.vendDelete('5002') ;      ttsbegin; delete_from jourSummary where jourSummary.VendAccount == #vendDelete; select firstonly forupdate vendTableDelete where vendTableDelete.AccountNum == #vendDelete; select firstonly forupdate vendTable where vendTable.AccountNum == #vend; vendTableDelete.merge(vendTable); vendTable.doUpdate(); vendTableDelete.doDelete();      ttscommit; }

Exporting data to Excel

As there are merits of a solution which depend on the situations and conditions in which they are used, I am suggesting one more alternate for achieving the objective i.e. Exporting data to Excel. In this solution we will make use of standard AX’s Reports and the concept of exporting the report data to an Excel file. I assume that we all understand that any standard AX report can be sent to a variety of Output devices such as Printer,Screen,Fax,File ( CSV,TXT,PDF,EXCEL etc) . The disadvantage in this is that the report headers is repeated after every page break and that is an undesired part . In the following walkthrough we will get over this problem as well as restrict the output to a file so that it gives a look and feel of an data export functionality. We will create a sample report for exporting the Price agreements data to Excel Start creating a report in AOT as per the following steps : Step 1: Create a class as shown below in which we would declare objects. ...

Ax 2009 FTP

static void readFromFTP() {     object                                        ftpo;     System.Net.FtpWebRequest     request;     System.IO.StreamReader          reader;     System.Net.NetworkCredenti al credential;     System.Net.FtpWebResponse   response;     System.String                            text;     ;     ftpo = System.Net.WebRequest::Cre ate(" ftp:/ /ftp.iso.com/i ntro.html " );     request = ftpo;   //  credential = new System.Net.NetworkCredenti al("user", "pass...

Append a txt file to another txt file

Copy this method to your Global Class in AX. public static void appendTextFile(str fromFilePath,str toFilePath) {     FileIOPermission fromPerm;     FileIOPermission toPerm;     System.String text;     System.IO.FileStream fs;     System.IO.StreamReader reader;     ;     if(System.IO.File::Exists(fromFilePath) && System.IO.File::Exists(toFilePath))     {          // Read text from file         reader = new System.IO.StreamReader(fromFilePath);         text = reader.ReadToEnd();         reader.Close();         // Append         System.IO.File::AppendAllText(toFilePath,text);     }     else     {         throw error("Invalid path or file does not exist");     } }

Dynamics AX 2009: FTP Adapter for AIF

from Markus Nöbauer The Application Integration Framework in Dynamics AX is an extensible framework for data transportation and reception. It support the separation of transport technology (e.g. MSMQ, XML/SOAP Webservices, Filesystem Share) security aspects (services, permissions, transported data) and data manipulation. Creating new adapters to support other transport technologies is simple. Here is an example to support FTP. Develop AIF FTP Adapter First, create a new parameter table AifFTPParameters to store FTP server name, user, password and directory (4 strings). Next create a setup form for the AifFTPParameters table and a display menu item. Add an OK command button. Add this code to the buttons clicked event: void clicked() {;     super();     // use the server name as selected value      element.closeSelect(Setup_ServerName.text()); } Create a new AifFTPSendAdapt...

Export and import Dynamics Ax labels

static void ExportLabels(Args _args) { str module = "TUS"; str exportFile = "\\\\tsclient\\c\\fil1.txt"; Label l; str s; int i; System.IO.TextWriter tw; ; l = new Label(); i = 0; tw = new System.IO.StreamWriter(exportFile); while(i < 9999) { s = l.extractString("@" + module + int2str(i)); if(substr(s,1,1) != '@') tw.WriteLine("@" + module + int2str(i) + ";" + s); i++; } tw.Close(); } static void ImportLabels(Args _args) { str module = "TUS"; str importFile = "\\\\tsclient\\c\\fil2.txt"; Label l; str s; System.IO.TextReader tw; System.String ss; str labelid, labeltext; int i; str existingLabel; ; l = new Label(); tw = new System.IO.StreamReader(importFile); ss = tw.ReadLine(); while(ss) { s = ss; i = strScan(s, ";", 1, 10); ...

Job to export all AX 2009 security groups to files

Alex wrote a nice and quick job that can export the existing security settings in Dynamics AX 2009 to a folder This is very helpful when we make frequent changes to security and need to have a quick backup of the existing settings. I have been changing security a bunch lately and it's nice to have a backup of your previous settings if you make a mistake. Here is a quick job I wrote to export your existing security settings to a folder.   static void ExportSecurityGroups(Args _args) {   SysSecurityUserGroup sysSecurity = SysSecurityUserGroup::construct();   UserGroupInfo userGroupInfo;   #file Dialog dialog = new Dialog( "@SYS14863" );   DialogField dialogFileName;   Object formdialog;   ;   dialogFileName = dialog.addField(typeid(FilePath), "@SYS16423" );   dialog.doInit();   formdialog = dialog.formRun();   for...

calculate total sales order or sales quotation amount / discounts / tax etc., through code( X++ ) in AX

this can be achieved through code using SalesTotals class. Check out the below code snippet. SalesTotals   salesTotals; SalesTable   salesTable; container   displayFields; str     totalTax, amountWithoutTax, amountInclTax; salesTable = salesTable::find('SO-1112345'); salesTotals = SalesTotals::construct(salesTable, salesUpdate::All); salesTotals.calc(); displayFields = salesTotals.displayFieldsCurrency( salesTotals.currencyCode() ); amountWithoutTax = conpeek(displayFields, TradeTotals ::posBalance()); amountInclTax   = conpeek(displayFields, TradeTotals::posTotalAmount()); totalTax    = conpeek(displayFields,TradeTotals::posTaxTotal()); In the above way, we can get all the values available in the totals form in the Sales Order Form by changing the TradeTotals values. We can get the values in the desired currency by providing a valid currency as a parameter to the displayFieldsCurr...

Send message to online user in Dynamics AX

static void sendAlert(Args _args) { EventInbox inbox; EventInboxId inboxId; inboxId = EventInbox::nextEventId(); inbox.initValue(); inbox.ShowPopup = NoYes::Yes; inbox.Subject = "Message to online user"; inbox.Message = "Message you want to send to user"; inbox.SendEmail = false; inbox.UserId = curUserID(); inbox.InboxId = inboxId; inbox.AlertCreatedDate = systemdateget(); inbox.AlertCreateTime = timeNow(); inbox.insert(); }

How to read a CSV , txt file in AX 2009

1. First of all, make sure that the file is accessible and has sufficient permissions to read the file. 2. Now follow the below code which reads the file, reads all the lines in the file and inserts into the table. #File CommaIo aSCIIFile; Container recordsCon; FileIoPermission               perm; StudentTable                    studentTable; #define.ExampleFile(@"c:\test.txt") ; perm = new FileIoPermission(#ExampleFile, #io_read ); if (perm == null) { return; } // Grants permission to execute the CommaIo.new method. // CommaIo.new runs under code access security. perm.assert(); // BP deviation documented. aSCIIFile = new CommaIo( #ExampleFile ,#io_read); ttsbegin; while (aSCIIFile.status()== IO_Status::Ok) //Reading the ASCII file if records are there ...