Sunteți pe pagina 1din 12

Modify Dynamics AX Standard Excel Import to Include - Update existing records - rule

door Microsoft Dynamics AX (Notities) op vrijdag 3 juni 2011 om 14:36


Sometimes we need to import an excel file that contains existing and new records. With
standard Dynamics AX 2009 you don't get an option (import rule) where you can specify
ONLY import and update existing records. Below are standard AX excel import rules...

To add a rule that says "Update existing records" only.


Modify Enum SysDataExcelImportRule to add a new element for update.

Note: If you noticed I have inserted new Enum element with value 101, which is far away
what Microsoft is using. It is a best practice to keep some difference between the enum values,
so if Microsoft inserts new standard enum elements later then our custom enum element do
not overlap with the standard. It helps when you upgrade your AX system in future.
Modify Class SysDataImportExcel, method ImportData as stated below. Just add lines
having related modification comments.
1:
switch (importRule)
2:
{
3:
//#N by Rahul Sharma on 19Apr2011 for
RAH_ExcelImportRule_UpdateOnlyOption
4:
//added update only option
5:
case SysDataExcelImportRule::RAHUpdate :
6:
case SysDataExcelImportRule::InsertAndUpdate :
7:
selectForUpdate = true;
8:
9:
case SysDataExcelImportRule::InsertNew :
10:
updCommon = this.recordExist(_dictTable, _curcommon,
selectForUpdate);
11:
break;
12:
}

1:
if (updCommon.RecId)
2:
{
3:
//existing standard code
4:
}
5:
else
6:
{
7:
//#N by Rahul Sharma on 19Apr2011 for
RAH_ExcelImportRule_UpdateOnlyOption
8:
//break if its a new record
9:
if (importRule == SysDataExcelImportRule::RAHUpdate)
10:
return false;
11:
12:
selectForUpdate = false;
13:
updCommon = _curcommon;
14:
}

After these small changes, you now should be able to import and update only existing records
using standard AX excel import.

You can download the AX Project from here.


http://www.axaptapedia.com/DEV_SysTableBrowser

Dynamics Ax: Learn in doing - Ajit


kumar's
Don't learn to do.. But Learn in doing

SATURDAY, OCTOBER 20, 2012

Data dictionary and Tables (in Dynamics AX)

Data Dictionary can be defined as the data model for the Axapta application.
The data in an Axapta installation is stored in a relational database. In short, this means that
data is separated in tables to prevent redundant data occurring and relations are defined
between the tables making it possible to gain access to the related data.

Tip:

An Axapta installation uses either a Microsoft SQL Server or an Oracle database for
storing data.
Tables, views, fields and indexes are synchronized to the database when created,
changed or deleted from Axapta. This definition of the data, is the only information
about the data dictionary stored in the database, the actual data is physically stored
within the Microsoft SQL Server or Oracle database

Whenever we face any synchronization problems, the primary effective solution could be
Running a Check/Synchronize in the SQL tool located in the main menu under
Administration | Periodic | SQL Administration > Table actions ->
Check/Synchronize button will be useful.

There are three main categories of Tables:


1. Application Tables
2. System Tables
3. Temporary Tables
Application Tables:

These are user tables and are used to define and build the application modules.
We can add a new field either to an Existing Table or to a New Table.
If we add a new field to an existing table, then the new field is adding in the existing
layer even though the modified table belongs to some other layer. (goes for all objects
on a Table, except the delete actions) This is really an advantage while upgrading an
application to a new release, because, we will only have to manually merge nodes
modified in more than one layer.

System Tables:

As the name suggests, these tables are created in the Kernel of the application. They contain
information specific to operation of Axapta infrastructure.

System tables are non-changeable. You cannot modify the data model of a system
table.
System tables can be found in the AOT under the node SystemDocumentation/Table.
Their purpose is to handle tasks such as keeping the database in sync with the
application, handling licensing and user information
Note: The system table SysLastValue stores usage data. This table is frequently used in the
application as it stores the last user settings for an object. But we might not see SysLastValue
declared from code, as the table is wrapped in the runbase framework or used by the class
xSysLastValue.

Temporary Tables:

The table property Temporary determines whether a table is temporary or not. And
any application table can be set to temporary by setting the table property Temporary
to Yes.
Caution: Setting a table containing data to temporary will cause existing data to be
deleted.
A temporary table contains no data and is not synchronized to the database. A
temporary table may be used as any normal table in joins and selects.
To easily locate temporary tables in the AOT, all temporary tables are prefixed with
Tmp*.
The major reason for using temporary tables is for the sorting of data. You might have
to present data using a specific sort in a form/report which cannot be accomplished
using a select statement or a query. Instead you can create a temporary table, by
fetching data from the tables and insert according to the sort requirement. As long the
temporary table is in scope, the temporary table will contain data.
The content of a temporary table is stored in the file system as a temporary file.

It will initially take a longer time to load the form data-sourced with temporary tables,
but the application will perform much faster once the data is loaded and thereby
provide a more user-friendly system.

Table Browser:

Table browser is quite handy to get an overview of the data in the table.
Table browser can be accessed by right-clicking on any table in the data dictionary
(Add-Ins > Table browser)
The table browser is created using a standard form which is called SysTableBrowser.
This can be used for creating/updating records in a table for Testing purposes.
Whereas, this cannot be used as an application user tool, because, data entered
through table browser will be only validated upon the business logic mentioned in the
Table scripts and not the business logic that could possibly be mentioned in the Form
methods. So Only the form which has been created within Axapta must be used to key
in live data for tables.

http://ajstudi0.blogspot.nl/search?updated-min=2013-01-01T00:00:00%2B05:30&updatedmax=2014-01-01T00:00:00%2B05:30&max-results=21

Form browser for Dynamics AxTables


In this example I am going to illustrate, a Form will be displayed, from the Tables Context
Menu. The form will show the records from selected table. We can call this form as Form
Browser for tables.

I had created the following Class for displaying the Form browser from AOT-Tables.
class PSShowFormForTable
{
}
void createForm(TableId mytableId)
{
#AOT
Args
args;
FormBuildDesign
formBuildDesign;
Form
form;
Formrun
formrun;
FormTabControl
formTabControl;
FormGroupControl
formGroupControl;

FormGridControl
formGridControl;
FormBuildDataSource formBuildDataSource;
TreeNode
treeNodeForm;
TreeNode
treeNodeTable;
TreeNode
treeNodeField;
TreeNodeIterator
iterator;
FormBuildTabControl formBuildTabControl;
FormBuildTabPageControl formBuildTabPageControl;
FormBuildTabPageControl formBuildTabPageControl2;
FormBuildGridControl formBuildGridControl;
str
fieldName;
str
caption;
str
myTableName;
int
i;
DictTable
dictTable;
;
dictTable = new DictTable(mytableId);
form = new Form();
form.name(dictTable.name());
myTableName = tableId2Name(mytableId);
formBuildDataSource = form.addDataSource(myTableName);
formBuildDataSource.table(mytableId);
formBuildDataSource.allowCreate(true);
formBuildDataSource.allowDelete(true);
formBuildDataSource.allowEdit(true);
formBuildDesign = form.addDesign("Design");
formBuildDesign.topMode(); // Auto
formBuildDesign.leftMode(); // Auto
formBuildDesign.widthMode(); // Auto
formBuildDesign.heightMode(); // Auto
formBuildDesign.windowType();
formBuildDesign.caption(dictTable.name());

formBuildDesign.titleDatasource(formbuilddatasource.id());
// Add tabbed page controls, a grid control, and string controls.
formBuildTabControl =
formBuildDesign.addControl(FormControlType::Tab, "Overview");
formBuildTabPageControl =
formBuildTabControl.addControl(FormControlType::TabPage, "Overview");

formBuildTabPageControl.caption("Overview");
formBuildTabPageControl2 =
formBuildTabControl.addControl(FormControlType::TabPage,"Details");
formBuildTabPageControl2.caption("Details");
formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::GRID,
"Grid");
formBuildGridControl.dataSource(myTableName);
formBuildGridControl.widthMode(1); // Column width
formBuildGridControl.heightMode(1); // Column height
treeNodeTable=TreeNode::findNode(#TablesPath + "\\" + myTableName + "\\Fields");
iterator=treeNodeTable.AOTiterator();
treeNodeField =iterator.next();
while(treeNodeField && i <=6 )
{
fieldName=treeNodeField.treeNodeName() ;
if (i==6)
{
formBuildTabPageControl2.addDataField(formBuildGridControl.dataSource(),
fieldname2id(tablename2id(myTableName),fieldName));
}
else
{
formBuildGridControl.addDataField(formBuildGridControl.dataSource(),
fieldname2id(tablename2id(myTableName),fieldName));
}
treeNodeField = iterator.next();
i++;
}
args = new Args();
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
client static void main(Args args)
{
tableId
tableId;

SysContextMenu
sysContextMenu;
TreeNode
treeNode;
PSShowFormForTable psShowFormForTable;
;
if (SysContextMenu::startedFrom(args))
{
sysContextMenu = args.parmObject();
treeNode
= sysContextMenu.first();
tableId
= SysTableBrowser::treeNode2TableId(treeNode);
}
if (tableId)
{
psShowFormForTable = new PSShowFormForTable();
psShowFormForTable.createForm(tableId);
}
}
Creation of ContextMenu for above class:
Drag the above class to the action menu items, for creating the action menu item.
AOT Menu ItemsAction
Provide the label as Form browser and save this action menu item.
Place this action menu item under SysContextMenu.
Open SysContextMenu from AOTMenus then drag and drop the above action menu item
to the SysContextMenu as shown in below figure.

We have to show this context menu item for tables only, not for all the objects in AOT.
For this go to the following method.
AOT ClassesSysContextMenuverifyItem
Add the following code under the MenuItemType Actions case
case MenuItemType::Action:

case menuitemactionstr(PSShowFormForTable):
if (_firstType &&_firstType == UtilElementType::Table)
{
return 1;
}
return 0;
Note: Here on the Form browser I am showing only 6 fields on Overview tab and 1 field on
Details tab.
Depends on the requirement, we can change the number of fields in above class.

Advantage: The table browser will be opened with in the Ax, whereas this form browser will
be opened outside of Ax work space (as Ax-Forms). We can do the analysis on the table data
in form browser very easily.

Easy Extended AX Table-Browser


Easy Extended AX Table-Browser
During implementations and regular developments in AX, I observed that many
consultants/developers open the tables from AOT in the Table-Browser and by hand
attempt to add/delete the records by hitting Ctrl+N/Alt+F9 keys and often copies the
records from the table-browser and paste them to excel for
checking/saving/printing/... the table data. The distress of manually copying/pasting
of records and recalling the control-keys can be avoided by simply extending the
Table-Browser by adding the Standard data Toolbar to the form
Step-1: Go to the AOT and select \Forms\SysTableBrowser\Designs\Design
and then change the design property WindowType value from Popup to Standard

Fig1: Changing WindowType property value to Standard


Step-2: Save and compile the SysTableBrowser Form after changing the WindowType
property value

Fig2: The original Table-Browser (WindowType property is Popup)

Fig3: Easy Extened Table-Browser with Standard-Toolbar (WindowType property is


Standard)
Thats it, enjoy the easy extended table-browser with the standard toolbar with all
table/record action features
http://axaptian.blogspot.com/

S-ar putea să vă placă și