Inside MS Dynamics AX 4.0 and MORPHIX IT
Inside MS Dynamics AX 4.0: http://www.4shared.com/file/hI4Hbnn7/MicrosoftPressInsideMicrosoftD.html? MORPHIX IT: http://www.4shared.com/file/hI4Hbnn7/MicrosoftPressInsideMicrosoftD.html?
CRUD operation in Dynamics AX 2009 through .Net business connector
Friends, rather going into more details about “How to’s” of accessing Dynamics AX through .Net, my main objective is to share my experience of performing CRUD operations in Dynamics AX 2009 through .Net BC. Here is a sample code; // CREATE OR INSERT SAMPLE // Create the .NET Business Connector objects. Axapta ax; AxaptaRecord axRecord; string tableName = “AddressState”; try { // Login to Microsoft Dynamics AX. ax = new Axapta(); ax.Logon(null, null, null, null); // Create a new AddressState table record. using (axRecord = ax.CreateAxaptaRecord(tableName)); { // Provide values for each of the AddressState record fields. axRecord.set_Field(“NAME”, “MyState”); axRecord.set_Field(“STATEID”, “MyState”); axRecord.set_Field(“COUNTRYREGIONID”, “US”); axRecord.set_Field(“INTRASTATCODE”, “”); // Commit the record to the database. axRecord.Insert(); } } catch (Exception e) { Console.WriteLine(“Error encountered: {0}”, e.Message); // Take other error action as needed. } // READ SAMPLE // Create the .NET Business Connector objects. Axapta ax; AxaptaRecord axRecord; string tableName = “AddressState”; // The AddressState field names for calls to // the AxRecord.get_field method. string strNameField = “NAME”; string strStateIdField = “STATEID”; // The output variables for calls to the // AxRecord.get_Field method. object fieldName, fieldStateId; try { // Login to Microsoft Dynamics AX. ax = new Axapta(); ax.Logon(null, null, null, null); // Create a query using the AxaptaRecord class // for the StateAddress table. using (axRecord = ax.CreateAxaptaRecord(tableName)); { // Execute the query on the table. axRecord.ExecuteStmt(“select * from %1″); // Create output with a title and column headings // for the returned records. Console.WriteLine(“List of selected records from {0}”, tableName); Console.WriteLine(“{0}t{1}”, strNameField, strStateIdField); // Loop through the set of retrieved records. while (axRecord.Found) { // Retrieve the record data for the specified fields. fieldName = axRecord.get_Field(strNameField); fieldStateId = axRecord.get_Field(strStateIdField); // Display the retrieved data. Console.WriteLine(fieldName + “t” + fieldStateId); // Advance to the next row. axRecord.Next(); } } } catch (Exception e) { Console.WriteLine(“Error encountered: {0}”, e.Message); // Take other error action as needed. } // UPDATE SAMPLE // Create an Axapta record for the StateAddress table. axRecord = ax.CreateAxaptaRecord(tableName); // Execute a query to retrieve an editable record where the name is MyState. axRecord.ExecuteStmt(“select forupdate * from %1 where %1.Name == ‘MyState’”); // If the record is found then update the name. if (axRecord.Found) { // Start a transaction that can be committed. ax.TTSBegin(); axRecord.set_Field(“Name”, “MyStateUpdated”); axRecord.Update(); // Commit the transaction. ax.TTSCommit(); } // DELETE SAMPLE // Execute a query to retrieve an editable record // where the name is MyStateUpdated. axRecord.ExecuteStmt(“select forupdate * from %1 where %1.Name == ‘MyStateUpdated’”); // If the record is found then delete the record. if (axRecord.Found) { // Start a transaction that can be committed. ax.TTSBegin(); axRecord.Delete(); // Commit the transaction. ax.TTSCommit(); }
How to reuse table Id in Dynamics AX
Sometime we created tables just for testing purpose within AOT and later on we delete these tables. In such cases we don’t care about the IDs which are created for each table. There is a way to use these system generated IDs for other newly created tables. You can do this by following steps; 1. Export the table with its current id. 2. Delete the table 3. Edit the xpo file and change the id to what you want 4. Import the xpo file with the id option checked. As long as the id is not used by something else, then it should get imported with that id.
Dynamics AX 2009: How to retrieve table properties
Here is the sample code to retrieve table properties in Dynamics AX 2009. static void TableProperties(Args _args) { Dictionary dictionary; TableLabel tableLabel; SysdictTable dTable; TreeNode Tnode; ; //initilize the data dictionary dictionary = new Dictionary(); // Replace _tableId parameter with the actual table id dTable = new SysDictTable(_tableId); // initilize the tree node to traverse each property of the table tNode = dTable.treeNode(); // Replace “Label” with any property name of the table. In this case I am getting table label and it will return label id tNode.AOTgetProperty(“Label”); // Get actual label from label file print sysLabel::labelId2String(tNode.AOTgetProperty(“Label”)); pause; }
Secure your MS Dynamics AX
Data security has always been the main concern of every organization, implementing MS Dynamics AX. I will not increase the length of the post by going into details of “How to’s” of security setup in Dynamics AX. Attached manual is providing the brief of security and is very useful to understand the basics of security in AX. Microsoft Dynamics Ax Security
Refresh DataSource and retain position
This post has been copied from http://devexpp.blogspot.com/2012/02/refresh-datasource-and-retain-position.html Refresh a DataSource is a very common task to Dynamics AX developers, as you’ll most likely perform changes on a record and have to present it to the user, on a form. The most commonly used method to refresh the DataSource to make a form show what you have changed on a record is the research method. The only problem is that the research method doesn’t retain the record that was selected, it positions the DataSource on the first record of the result, causing the user to see another record. To resolve this matter, the research method, only in Dynamics AX 2009, has a boolean parameter, retainPosition. Now if you call it by passing true to it, it will sure retain the position of the selected record after the refresh, right? Wrong… This should only work when your form has DataSources linked by Inner Joins in it, what means that the generated query has Inner Joins in it. Having any other link types or temporary tables causes it to not retain the position, even if you pass true when calling it. So I’ll present you two ways of retaining the position of the selected record, one that works sometimes, and one that always works, although you should always try and see if it works with research(true) before trying anything else. On the first way, you could simply get the position of the DataSource before calling research(), like this: int position; ; position = myTable_ds.getPosition(); myTable_ds.research(); myTable_ds.setPosition(position); But does this work perfectly? Not again… The code above should select the record that was on the previously selected record’s position. What does that mean? It means that if your query result changes the record’s orders, you won’t have the correct record selected. This could easily happen if your form handles the records’ order in a special way, or if the action is performed when the record or any records are inserted, which will certainly cause the the form to reorder the records when you tell it to refresh the DataSource. The second way to do it will actually look for the correct record and then select it, so you can imagine it will perform a little worse than the others, but at least it will never fail (unless you, somehow, delete the record you’re looking for in the meantime). Simply copy the RecId from the record you want to keep selected to a new table buffer, like this: MyTable myTableHolder; ; myTableHolder.RecId = myTableRecord.RecId; myTable_ds.research(); // or: myTableRecord.dataSource().research(); myTable_ds.findRecord(myTableHolder); // or: myTableRecord.dataSource.findRecord(myTableHolder); We copy if to a new table buffer because the findRecord method expects a parameter of type Common. If you stored the RecId in a variable, you would have to pass it to a table buffer anyway… And that’s it, it’ll first refresh the DataSource, and then look for your record and select it, so the screen might even “blink” for a second. As I said, this is not the best when thinking about performance, but at least it works…
Get and Set values implicitly in web control in EP
DataSetViewRow row; row = AxDatasource.GetDataSet().DataSetViews[“DataSetViewName”].GetCurrentRecord(); // Get old value row.GetFieldValue(“FieldName”); // Set new value row.BeginEdit(); row.SetFieldValue(“FieldName”, NewValue); row.EndEdit();
Retrieving data from AX table in EP
Sometime we are in need of retrieving data from the tables which are not added in form’s datasource in EP page. To manipulate the data from tables other than datasource (in EP) or dataset (in AX), following code will work.
Microsoft Dynamics AX Code Samples
Here you can have the list of code sample of Microsoft Dynamics AX, AIF and EP http://archive.msdn.microsoft.com/axcodesamples
How to: Test User Controls in Visual Studio [AX 2012]
It really made the process faster to test the user control without going to EP pages and refresh the AOD and data files again and again. http://msdn.microsoft.com/en-us/library/cc616458.aspx
