Skip to main content

Posts

Showing posts from August, 2012

How to set the language used on a report

When printing a report, Ax sets the used language automatically based on the user's settings. The selection of available languages for the client interface depends on the installed language license keys. But sometimes, it may be necessary to change the default settings for reports. With reports needed for external use for example. Like invoices and packings slips you send to your customers. These documents require to be made up in the language of your customer. Ax is designed with this scenario in mind. The language to use in the report can be set with following command: element.design().languageID(); So for example: element.design().languageID('en-us'); Place the code in the init method of your report, or in the fetch method. You can use this in your own custom reports as well, with no limitation regarding the language license keys you bought. All you need are the appropriate label files. (Otherwise you get error messages like 'label @SYS12...

Getting label text in different languages

When printing a report, Ax sets the used language automatically based on the user's settings. The selection of available languages for the client interface depends on the installed language license keys. But sometimes, it may be necessary to change the default settings for reports. With reports needed for external use for example. Like invoices and packings slips you send to your customers. These documents require to be made up in the language of your customer. Ax is designed with this scenario in mind. The language to use in the report can be set with following command: element.design().languageID(); So for example: element.design().languageID('en-us'); Place the code in the init method of your report, or in the fetch method. You can use this in your own custom reports as well, with no limitation regarding the language license keys you bought. All you need are the appropriate label files. (Otherwise you get error messages like 'label @SYS1...

Encryption and decryption in AX

When handling some high security data like password etc. its always better to use the encryption – decryption methodology. This small example shows this methodology in AX. It uses TextBuffer class of AX To encrypt a string, use the following code: TextBuffer textBuffer = new TextBuffer(); ; textBuffer.setText(_text); textBuffer.encrypt(987654123); // Basic encryption To decrypt a string, use the following code: TextBuffer textBuffer = new TextBuffer(); ; textBuffer.setText(_text); textBuffer.decrypt(987654123); decryptedString = textBuffer.getText(); In these examples, the encryption key is 987654123. This can be any integer.

Integration with word

In this section i am going to write about word integration with AX. Let us first start with a small example to show how it all really works. Below is the piece of code which opens up a specified document and gets the data written in it. static void getWordData(Args _args) { COM document; COM wordDocument; COM range; COM app; ; app = new com("Word.Application"); document = app.Documents(); wordDocument = document.add(‘E:\\Docs\\Extend the Alerts Functionality.doc’); range = wordDocument.range(); info(range.text()); app.quit(0); } Here we use Word.Application COM class for integration with word. We open the document "Extend the Alerts Functionality.doc’ and display its contents in the infolog. Now let us go ahead with opening a word document and writing data in it through AX. Below is a small piece of code that will open a word document and write "Example of word integration with A...

All about queries

The query object model contains classes to define and run a query. These objects are used to define the query data source, the fields returned, record ranges and relations to child data sources. The following illustration shows the object model. The query components shown in the previous figure are system classes. The query classes are more visible when you create a dynamic query in code, but they are also used behind the scenes when you create a static query in the AOT. System class Description QueryRun Executes the query and fetches the data. Query The top level of the query definition. This class holds some properties itself and has one or more related data sources. QueryBuildDataSource Defines access to a single data source in the query. If more than one data source exists at the same level in a query, they result in separate SQL statements that are executed sequentially. If one data source exists as a child of another data source, a join is created between the two data so...

Email techniques in AX 4.0

In this article, I am going to demonstrate different email techniques that can be used in AX 4.0. Following classes can be used to send an email Mapi and its related classes SysMailer SysInetMail SysEmailBatch SmmOutlookEmail MAPI technique: Following code demonstrates the usage of mapi class for sending email. It uses outlook to send mail. static void emailThruMapi(Args _args) { MapiEx mapiEx; MapiExMail mapiExMail; boolean mapiInitialised; COM outlook; COM item; COM outlookNameSpace; COM folder; COM attachments; str storeId; str entryId; #define.outlookapplication(‘Outlook.Application’) #define.mapi(‘Mapi’) #smmMSOutlook2002ObjectModelConstants #define.htmlText(‘ Hi There ’) ; outlook = new COM (#outlookapplication); outlookNameSpace = outlook.getNameSpace(#mapi); outlookNameSpace.logon(); folder = outlookNameSpace.getDefaultFolder(#olFolderInbox); item = outl...

Restoring delete sales order or purchase order

Many people know that when a sales order or purchase order is deleted, it is actually not purged from system like lot of other data but sits in the voided tables. These orders can be viewed from AR -> Inquiries -> History -> Voided sales order or AP -> Inquiries -> History -> Voided sales order. Now from this form you can only view the deleted orders but there is not option of restoring them. Below are some sample code that can be used to restore the voided orders. Sales order restoration: static void restoreDeletedSO(Args _args) { SalesTableDelete salesTableDelete; SalesLineDelete salesLineDelete; SalesTable salesTable; SalesLine salesLine; ; SalesTableDelete = SalesTableDelete::find(’00450_036′, true); ttsbegin; switch (salesTableDelete.Cancelled) { case Voided::Voided : salesTable = conpeek(salesTableDelete.SalesTable, 1); salesTable.insert(); while select forupdate salesLineDelete where salesLineDe...

Connecting to Databases through X++

In this article, I am going to explain about different ways through which one can connect to different databases for data manipulation operations. In AX, the methods that I know are following. Please feel free to add more methods that you feel are also available. ODBC Connection ADO Connection OleDB Connection Connection class Let us go through each of these options one by one. ODBC Connection: ODBC stands for Open Data Base Connectivity. It is a connection that is created to define a connection between a computer and a database stored on another system. The ODBC connection contains information needed to allow a computer user to access the information stored in a database that is not local to that computer. In Dynamics AX, we have ODBCConnection class to carry out this type of database connection need. This class uses LoginProperty class for login information and uses Statement and ResultSet classes for carrying out DML operations. Below is an example of how to use this cla...

Listing out Published SQL Servers in AX

I had a requirement where I had to populate list of SQL Servers in a table in AX and all this had to be done from within AX. I couldn’t find any support directly in AX, so I decided to use .Net classes for this purpose. Here is a job that can help you achieve the same. static void getListOfSQLServers(Args _args) { System.Data.Sql.SqlDataSourceEnumerator dataEnum; System.Data.DataTable dataTable; System.Data.DataRowCollection collection; System.Data.DataRow row; System.Object serverObj, instanceObj; int sqlCount, i; str serverName, instanceName; ; dataEnum = System.Data.Sql.SqlDataSourceEnumerator::get_Instance(); dataTable = dataEnum.GetDataSources(); collection = dataTable.get_Rows(); sqlCount = collection.get_Count(); for (i = 0; i < sqlCount; i++) { row = collection.get_Item(i); serverObj = row.get_Item(...

Handling RecIds in SQL Server

Insight Into Record IDs 17 Sep Record IDs are unique IDs. In AX 4.0 Record id is unique for a table, a significant shift in 4.0 when compared to 3.0 where record ids were unique across the application. This allows AX to store more data and support enormous number of records. In AX 4.0 SystemSequences table stores record ids details for all the tables in AX. The generation of Record ids is handled by class SystemSequence. Record ids are generated at the time of saving the record. This is what system does. based on the table id, ID = -1 and name =’SEQNO’ system gets a block of record ids and caches them and stores in the client. The block is of size 250 (in 3.0 we could change the block size, but in 4.0 MS doesnt allow anybody to change the block size). Here is a sample code that shows how we can get next record id in AX 4.0 static void getNextRecIdAX40(Args _args) { //Table that stores record ids details for tables SystemSequences systemSequences; //Class that handles Record...