To let any field to be generated sequentially you must do the following:
Suggest i have a table named NoobsTable and a field named NoobId, the extended data type for NoobId is NoobEDT
and i have a Form named NoobsForm
1) For example if the NoobsForm is located in Inventory managment Module you should find the class named NumberSeqReference_Inventory, then go to LoadModule method in that class and write the following at last:
numRef.dataTypeId = typeId2ExtendedTypeId(typeid(NoobEDT)); //Extended datatype related to NoobId.
numRef.referenceHelp = literalStr("HelpText"); // Your help text to be viewed in Parameters later.
numRef.wizardContinuous = true;
numRef.wizardManual = NoYes::No;
numRef.wizardAllowChangeDown = NoYes::No;
numRef.wizardAllowChangeUp = NoYes::No;
numRef.wizardHighest = 99999999;
numRef.sortField = 1;
this.create(numRef);
2)Then go to Table node and find InventParameters, go to methods node then add a new method and write the following:
server static NumberSequenceReference numRefNoobId()
{
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(NoobEDT))); //Extended datatype
}
3)Then go to Inventroy managment content pane --> Setup --> Parameters --> Number Sequences Tab
now here you will see the Extended Data type NoobEDT and an empty Sequence number code, right click the empty lookup and click Go to the main table Form.
Add a new number sequence code in the opened form and save it [for example]:
Number sequence code: NoobNumberSeq
Name: NoobNumberSeq
Smallest: 1
Largest: 99999999
Next: 1
Format: Noob_########
InUse: Checked
Return to previous Form "Parameters" and choose NoobNumberSeq that we have just created it from Number sequence code lookup to NoobEDT Reference
3)Last thing to do is Go to NoobsForm --> Datasources node --> NoobsTable --> Methods, and override method (create) and write the following:
public void create(boolean _append = false)
{
;
super(_append);
NoobsTable.NoobId = NumberSeq::newGetNum(InventParameters::numRefNoobId(),true).num(); //numRefNoobId() is a method created in step 2)
}
//End
Finally go to the form and create a new record and you will see your number is generated automatically and sequentially.
Note: go to NoobsTable and set NoobId field to( AllowEdit:No AllowEditOnCreate:No ) if you dont want anyone to edit the generated number.
Wednesday, 16 November 2011
Friday, 11 November 2011
Microsoft Dynamics AX - X++ code to Read/Write data to excel
How to write data to Excel file
Follow mentioned instructions:
A. Use SysExcelApplication class to create excel file.
B. Use SysExcelWorkbooks and SysExcelWorkbook to create a blank workbook(by default 3 worksheets will be available).
C. Use SysExcelWorkSheets to select worksheet for writing data.
D. SysExcelCells to select the cells in the excel for writing the data.
E. SysExcelCell to write the data in the selected cells.
F. Once you done with write operation use SysExcelApplication.visible to open
file.
static void Write2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");
cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
application.visible(true);
}
Reading Data from Excel File
static void ReadExcel(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "C:\\item.xls";
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
info(strfmt('%1 - %2', itemId, name));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
Follow mentioned instructions:
A. Use SysExcelApplication class to create excel file.
B. Use SysExcelWorkbooks and SysExcelWorkbook to create a blank workbook(by default 3 worksheets will be available).
C. Use SysExcelWorkSheets to select worksheet for writing data.
D. SysExcelCells to select the cells in the excel for writing the data.
E. SysExcelCell to write the data in the selected cells.
F. Once you done with write operation use SysExcelApplication.visible to open
file.
static void Write2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");
cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
application.visible(true);
}
Reading Data from Excel File
static void ReadExcel(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "C:\\item.xls";
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
info(strfmt('%1 - %2', itemId, name));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
Friday, 4 November 2011
.NET Business Connector
.NET Business Connector is a component of the Microsoft Dynamics AX development environment. .NET Business Connector enables you to build software applications that integrate with Microsoft Dynamics AX. You can access data or start business logic. The advantage of using .NET Business Connector over other types of integration is that you use the same X++ code and business logic available to clients. You will also be able to use the Microsoft Dynamics AX security model. For more information about security
Application Integration Framework
.NET Interop from X++
.NET Interop to X++
There are different technologies for interoperation from .NET Framework code to X++ code:
.NET Business Connector
Proxy classes, written in C# or Visual Basic by Microsoft Visual Studio, which encapsulate an X++ class or table
Web services
Application Integration Framework
.NET Interop from X++
.NET Interop to X++
There are different technologies for interoperation from .NET Framework code to X++ code:
.NET Business Connector
Proxy classes, written in C# or Visual Basic by Microsoft Visual Studio, which encapsulate an X++ class or table
Web services
Map object in AX 2009
Map:
A Map object associates one value (the key) with another value. Both the key
and value can be of any valid X++ type, including objects. The types of the key
and value are specified in the declaration of the map. The way in which maps are
implemented means that access to the values is very fast.
Multiple keys can map to the same value, but one key can map to only one value
at a time. If a [key, value] pair is added where the key already exists, it will
replace the existing pair with that key value.
The following methods are commonly used on Map objects:
• insert(anytype _key, anytype _value) - Inserts an element (pair)
into the map.
• remove(anytype _key) - Removes a (key, value) pair from a map.
• exists(anytype _key) - Determines whether a particular value exists
as a key in the map.
• lookup(anytype _key) - Returns the value mapped to by a particular
key value.
• elements() - Returns the number of elements contained in the map.
• getEnumerator() - Returns a MapEnumerator object for this Map
object.
The MapEnumerator class allows you to traverse through the elements within a
map. The following methods are commonly used on MapEnumerator objects:
• currentKey() - Retrieves the key of the pair currently pointed to in
the map.
• currentValue() - Retrieves the value of the pair currently pointed to
in the map.
• moveNext() - Moves the enumerator to the next pair in the map.
Map enumerators start before the first pair in the map, so
moveNext() must be called to make it point to the first pair in the
map.
• reset() - Moves the enumerator to the start of the map.
Map Demonstration
Demonstration - Creating a Map
The following code and procedure demonstrates how to create a map of
Customers per State, then move through it and extract values from it:
1. Create a new Map object, specifying the data type it will contain.
2. Loop through the records in the CustTable. For each, use
Map.exists() to check if CustTable.State already exists as a key in
the map.
3. If it does not already exist, use Map.insert() to insert a pair of
(CustTable.State,1).
4. If it does already exist, use Map.insert() to re-insert the pair with the
same key (which will overwrite the existing pair), but the new value
equals the existing pair value plus 1.
5. Set the MapEnumerator object using the Map.getEnumerator()
method.
6. Go to the start of the map, using MapEnumerator.reset().
7. Move through the items in the list, using
MapEnumerator.moveNext().
8. Pull the value of the current item in the list, using
MapEnumerator.currentKey() and
MapEnumerator.currentValue().
Map mapStateNumbers;
MapEnumerator enumerator;
CustTable custTable;
;
mapStateNumbers = new Map(Types::String, Types::Integer);
while select custTable
{
if(mapStateNumbers.exists(custTable.State))
mapStateNumbers.insert(custTable.State,
mapStateNumbers.lookup(custTable.State) + 1);
else
mapStateNumbers.insert(custTable.State, 1);
}
enumerator = mapStateNumbers.getEnumerator();
while (enumerator.moveNext())
{
info(strfmt("%1 customers are located in %2",
enumerator.currentValue(), enumerator.currentKey());
}
A Map object associates one value (the key) with another value. Both the key
and value can be of any valid X++ type, including objects. The types of the key
and value are specified in the declaration of the map. The way in which maps are
implemented means that access to the values is very fast.
Multiple keys can map to the same value, but one key can map to only one value
at a time. If a [key, value] pair is added where the key already exists, it will
replace the existing pair with that key value.
The following methods are commonly used on Map objects:
• insert(anytype _key, anytype _value) - Inserts an element (pair)
into the map.
• remove(anytype _key) - Removes a (key, value) pair from a map.
• exists(anytype _key) - Determines whether a particular value exists
as a key in the map.
• lookup(anytype _key) - Returns the value mapped to by a particular
key value.
• elements() - Returns the number of elements contained in the map.
• getEnumerator() - Returns a MapEnumerator object for this Map
object.
The MapEnumerator class allows you to traverse through the elements within a
map. The following methods are commonly used on MapEnumerator objects:
• currentKey() - Retrieves the key of the pair currently pointed to in
the map.
• currentValue() - Retrieves the value of the pair currently pointed to
in the map.
• moveNext() - Moves the enumerator to the next pair in the map.
Map enumerators start before the first pair in the map, so
moveNext() must be called to make it point to the first pair in the
map.
• reset() - Moves the enumerator to the start of the map.
Map Demonstration
Demonstration - Creating a Map
The following code and procedure demonstrates how to create a map of
Customers per State, then move through it and extract values from it:
1. Create a new Map object, specifying the data type it will contain.
2. Loop through the records in the CustTable. For each, use
Map.exists() to check if CustTable.State already exists as a key in
the map.
3. If it does not already exist, use Map.insert() to insert a pair of
(CustTable.State,1).
4. If it does already exist, use Map.insert() to re-insert the pair with the
same key (which will overwrite the existing pair), but the new value
equals the existing pair value plus 1.
5. Set the MapEnumerator object using the Map.getEnumerator()
method.
6. Go to the start of the map, using MapEnumerator.reset().
7. Move through the items in the list, using
MapEnumerator.moveNext().
8. Pull the value of the current item in the list, using
MapEnumerator.currentKey() and
MapEnumerator.currentValue().
Map mapStateNumbers;
MapEnumerator enumerator;
CustTable custTable;
;
mapStateNumbers = new Map(Types::String, Types::Integer);
while select custTable
{
if(mapStateNumbers.exists(custTable.State))
mapStateNumbers.insert(custTable.State,
mapStateNumbers.lookup(custTable.State) + 1);
else
mapStateNumbers.insert(custTable.State, 1);
}
enumerator = mapStateNumbers.getEnumerator();
while (enumerator.moveNext())
{
info(strfmt("%1 customers are located in %2",
enumerator.currentValue(), enumerator.currentKey());
}
Subscribe to:
Posts (Atom)