Wednesday, 10 December 2014
Tuesday, 9 December 2014
Finding Table mandatory fields in AX 2012
static void MandatoryFields(Args _args)
{
SysDictTable dTable;
SysDictField dField;
Counter counter;
;
dTable = new SysDictTable(tablenum(CustTable));
for(counter =1; counter<= dTable.fieldCnt();counter++)
{
dField = new SysDictField(dTable.id(),dTable.fieldCnt2Id(counter));
if(dField.mandatory())
info(dField.name());
}
}
{
SysDictTable dTable;
SysDictField dField;
Counter counter;
;
dTable = new SysDictTable(tablenum(CustTable));
for(counter =1; counter<= dTable.fieldCnt();counter++)
{
dField = new SysDictField(dTable.id(),dTable.fieldCnt2Id(counter));
if(dField.mandatory())
info(dField.name());
}
}
Tuesday, 2 December 2014
Some Useful links to learn Dynamics Ax 2012
S.No
|
Contents
|
Descriptions
|
1
|
Static keyword
|
C# static-method |
2
|
Ax Versions
|
|
3
|
Ax Support
|
|
4
|
Query class
|
|
5
|
Tips and Enhancements
|
|
6
|
SSRS Challenges
|
|
7
|
Inbound Web Service
|
|
8
|
Number Sequence in 2012
|
|
9
|
AIF introduction
|
Microsoft Dynamics AX 2012 Services and Architecture |
10
|
Database Entity Relationship Diagrams
|
|
11
|
Table methods
|
|
12
|
Learn
|
|
13
|
Debugger
|
|
14
|
Creating Batch
|
|
15
|
Batch
|
|
16
|
Ax MS blog
|
|
17
|
|
|
18
|
Ax form methods
|
|
19
|
Currency Details
|
|
20
|
AX important Codes
|
|
21
|
Controller Class
|
|
22
|
Technical Blog
|
|
23
|
AX 2012 Models
|
|
24
|
Code to Store reports from ax 2 File
|
|
25
|
Sending std report to mail from ax 2012
R2
|
|
26
|
Sales/Purchase Form Letter Explanation
|
|
27
|
How to Change AOT objects in code
|
|
28
|
Document Services
|
|
29
|
Model Store & XPO Diff
|
|
30
|
Life cycle Servcies
|
|
31
|
Ax Services
|
|
Method to get the barcode in AX 2012
Method to get the barcode
private ItemBarCode getBarcodeString(ItemId _itemId, InventDimId _inventDimId)
{
ItemBarCode barCodeString;
BarcodeSetupId barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
;
barCodeString = InventItemBarcode::findByProductDimensions(_itemId,
InventDim::find(_inventDimId),
false,false,barcodeSetupId,false).itemBarCode;
return barCodeString;
}
Method to get the encoded barcode string
private BarCodeString getEncodedBarCodeString(ItemId _itemId, InventDimId _inventDimId)
{
BarCodeString EncodedBarCodeString;
BarcodeSetupId barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
BarcodeSetup barcodeSetup = BarcodeSetup::find(barcodeSetupId);
Barcode barcode = barcodeSetup.barcode();
ItemBarCode itemBarCode;
;
itemBarCode = this.getBarcodeString(_itemId, _inventDimId);
if (barcodeSetup.validateBarcode(itemBarCode))
{
barcode.string(true, itemBarCode);
barcode.encode();
}
else
{
throw(error(strfmt("@SYS41409", barcode.barcodeType(), itemBarCode)));
}
EncodedBarCodeString = barcode.barcodeStr();
return EncodedBarCodeString;
}
private ItemBarCode getBarcodeString(ItemId _itemId, InventDimId _inventDimId)
{
ItemBarCode barCodeString;
BarcodeSetupId barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
;
barCodeString = InventItemBarcode::findByProductDimensions(_itemId,
InventDim::find(_inventDimId),
false,false,barcodeSetupId,false).itemBarCode;
return barCodeString;
}
Method to get the encoded barcode string
private BarCodeString getEncodedBarCodeString(ItemId _itemId, InventDimId _inventDimId)
{
BarCodeString EncodedBarCodeString;
BarcodeSetupId barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
BarcodeSetup barcodeSetup = BarcodeSetup::find(barcodeSetupId);
Barcode barcode = barcodeSetup.barcode();
ItemBarCode itemBarCode;
;
itemBarCode = this.getBarcodeString(_itemId, _inventDimId);
if (barcodeSetup.validateBarcode(itemBarCode))
{
barcode.string(true, itemBarCode);
barcode.encode();
}
else
{
throw(error(strfmt("@SYS41409", barcode.barcodeType(), itemBarCode)));
}
EncodedBarCodeString = barcode.barcodeStr();
return EncodedBarCodeString;
}
Get Barcode based on Dimension in AX 2012
public BarCodeString encodeBarcode(CustPackingSlipTrans _custPackingSlipTrans)
{
BarcodeSetupId barcodeSetupId;
BarcodeSetup barcodeSetup;
Barcode barcode;
ItemBarCode itemBarCode;
barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
barcodeSetup = BarcodeSetup::find(barcodeSetupId);
barcode = barcodeSetup.barcode();
itemBarCode =InventItemBarcode::findByProductDimensions(_custPackingSlipTrans.ItemId,
InventDim::find(_custPackingSlipTrans.InventDimId),
false,false,barcodeSetupId,false).itemBarCode;
if (barcodeSetup.validateBarcode(itemBarCode))
{
barcode.string(true, itemBarCode);
barcode.encode();
}
else
{
throw(error(strfmt("@SYS41409", barcode.barcodeType(), itemBarCode)));
}
return barcode.barcodeStr();
}
{
BarcodeSetupId barcodeSetupId;
BarcodeSetup barcodeSetup;
Barcode barcode;
ItemBarCode itemBarCode;
barcodeSetupId = InventParameters::find().BarcodeSetupIdPick;
barcodeSetup = BarcodeSetup::find(barcodeSetupId);
barcode = barcodeSetup.barcode();
itemBarCode =InventItemBarcode::findByProductDimensions(_custPackingSlipTrans.ItemId,
InventDim::find(_custPackingSlipTrans.InventDimId),
false,false,barcodeSetupId,false).itemBarCode;
if (barcodeSetup.validateBarcode(itemBarCode))
{
barcode.string(true, itemBarCode);
barcode.encode();
}
else
{
throw(error(strfmt("@SYS41409", barcode.barcodeType(), itemBarCode)));
}
return barcode.barcodeStr();
}
Query Build classes in AX 2012
Introduction
The query statement in X++ is a primary method of retrieving and manipulating data in Microsoft Dynamics AX 2012. A query can be created in the AOT using the graphical user interface. The AOT query has an advantage of a quick and visual design, however, it may not be able to do what the more serious programmer needs. This article examines the components of query design in X++. The illustration builds from the Sales Table using the Contoso database set. The goal is to find the sales items from a specific confirmation date. The finished class is included at the end of the article so that you can simply cut and paste to test the code.
Query Components
The basic query builds the model through a series of required steps. First is the definition of the class variables, where you setup the name declarations for the classes to be used, in this case the query framework, run method, data source, and range. Second, build out the framework classes defining the query, datasource, and the range. Third, instantiate or actually create an active query for use. Fourth, you can now run the query, using the created query instantiated in step three.
Defining the Classes
The following variables are used when creating a query. Their name declarations need to occur at the top of the class. Notice the naming convention used for it is common in much of existing code within AX, however it may vary.
// The first step is to define the query variables that we will be using. This is building the framework.
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
The Build
The build of these objects is the next step. First, instantiate the query class to build the framework. Second, call to the query build data source class and specifically the addDatatsource method. Finally, define the range to set the query scope.
// Instantiates or creates the query framework.
query = new Query();
// Links the table to the datasource definition.
qbds = query.addDataSource(TableNum(SalesTable));
// Sets the range to be the ShippingDateConfirmed.
qbr = qbds.addRange(FieldNum(SalesTable, ShippingDateConfirmed));
The Instantiation
Instantiate the query using a three step statement combined in to one statement. This is taking the framework definition from previous steps, creating a new instance, and activating it for use.
queryRun = new QueryRun(query);
The Action
Queries wouldn’t be any fun unless there was some sort of action. In this case, the query will display a query form for the user. The user can then add their own number sequences or sorting preferences. This is ideal to create much more dynamic queries for form information or reporting.
// the If condition checks to see that the query is running. If not, it will not execute.
if (queryRun.prompt())
{
//The while loops over the SalesTable in search of the information needed.
while (queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
info(salesTable.SalesID);
}
}
}
Completed Query
The following three methods of the class ExaminingQueryBasic complete the query, with a few more extra commands to set the date and increase end user interactivity by adding a sorting field.
Declaration Method
public class ExaminingQueryBasic
{
SalesTable salesTable;
}
Main method
public static void main(Args args)
{
ExaminingQueryBasic eqb = new examiningQueryBasic();
eqb.queryfun();
}
QueryRun method
public void queryRun()
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
query = new Query();
qbds = query.addDataSource(TableNum(SalesTable));
qbr = qbds.addRange(FieldNum(SalesTable, ShippingDateConfirmed));
// notice the addition of a specific value for date.
qbr.value(’05/12/2008′);
// this creates an additional setup that the end user can change within the query form.
qbds.addSortField(FieldNum(SalesTable,SalesID));
queryRun = new QueryRun(query);
if (queryRun.prompt())
{
while (queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
info(salesTable.SalesID);
}
}
}
Conclusion
The X++ query is a robust tool to retrieve data. Along with the while and select statements, virtually any piece of the data in the system can be extracted for use in either forms or reports. This article examined the four components that are needed for a query to operate. With this primer, you too can create your own dynamic queries for use with Dynamics AX.
The query statement in X++ is a primary method of retrieving and manipulating data in Microsoft Dynamics AX 2012. A query can be created in the AOT using the graphical user interface. The AOT query has an advantage of a quick and visual design, however, it may not be able to do what the more serious programmer needs. This article examines the components of query design in X++. The illustration builds from the Sales Table using the Contoso database set. The goal is to find the sales items from a specific confirmation date. The finished class is included at the end of the article so that you can simply cut and paste to test the code.
Query Components
The basic query builds the model through a series of required steps. First is the definition of the class variables, where you setup the name declarations for the classes to be used, in this case the query framework, run method, data source, and range. Second, build out the framework classes defining the query, datasource, and the range. Third, instantiate or actually create an active query for use. Fourth, you can now run the query, using the created query instantiated in step three.
Defining the Classes
The following variables are used when creating a query. Their name declarations need to occur at the top of the class. Notice the naming convention used for it is common in much of existing code within AX, however it may vary.
// The first step is to define the query variables that we will be using. This is building the framework.
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
The Build
The build of these objects is the next step. First, instantiate the query class to build the framework. Second, call to the query build data source class and specifically the addDatatsource method. Finally, define the range to set the query scope.
// Instantiates or creates the query framework.
query = new Query();
// Links the table to the datasource definition.
qbds = query.addDataSource(TableNum(SalesTable));
// Sets the range to be the ShippingDateConfirmed.
qbr = qbds.addRange(FieldNum(SalesTable, ShippingDateConfirmed));
The Instantiation
Instantiate the query using a three step statement combined in to one statement. This is taking the framework definition from previous steps, creating a new instance, and activating it for use.
queryRun = new QueryRun(query);
The Action
Queries wouldn’t be any fun unless there was some sort of action. In this case, the query will display a query form for the user. The user can then add their own number sequences or sorting preferences. This is ideal to create much more dynamic queries for form information or reporting.
// the If condition checks to see that the query is running. If not, it will not execute.
if (queryRun.prompt())
{
//The while loops over the SalesTable in search of the information needed.
while (queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
info(salesTable.SalesID);
}
}
}
Completed Query
The following three methods of the class ExaminingQueryBasic complete the query, with a few more extra commands to set the date and increase end user interactivity by adding a sorting field.
Declaration Method
public class ExaminingQueryBasic
{
SalesTable salesTable;
}
Main method
public static void main(Args args)
{
ExaminingQueryBasic eqb = new examiningQueryBasic();
eqb.queryfun();
}
QueryRun method
public void queryRun()
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
query = new Query();
qbds = query.addDataSource(TableNum(SalesTable));
qbr = qbds.addRange(FieldNum(SalesTable, ShippingDateConfirmed));
// notice the addition of a specific value for date.
qbr.value(’05/12/2008′);
// this creates an additional setup that the end user can change within the query form.
qbds.addSortField(FieldNum(SalesTable,SalesID));
queryRun = new QueryRun(query);
if (queryRun.prompt())
{
while (queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
info(salesTable.SalesID);
}
}
}
Conclusion
The X++ query is a robust tool to retrieve data. Along with the while and select statements, virtually any piece of the data in the system can be extracted for use in either forms or reports. This article examined the four components that are needed for a query to operate. With this primer, you too can create your own dynamic queries for use with Dynamics AX.
Count number of records in a table in AX 2012
static void Query_cntRecords(Args _args)
{
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbd;
;
qbd = query.addDataSource(tablenum(CustTable));
queryRun = new QueryRun(query);
info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun)));
}
{
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbd;
;
qbd = query.addDataSource(tablenum(CustTable));
queryRun = new QueryRun(query);
info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun)));
}
AX 2012 job to run AOT Query
static void ExecAOTQuery(Args _args)
{
QueryRun queryRun;
Counter totalRecords;
;
queryRun = new QueryRun(queryStr(CreatedAOTQueryName));
if (queryRun.prompt())
{
while (queryRun.next())
{
totalRecords++;
}
}
info(strFmt(“Total Records : %1”, totalRecords));
}
{
QueryRun queryRun;
Counter totalRecords;
;
queryRun = new QueryRun(queryStr(CreatedAOTQueryName));
if (queryRun.prompt())
{
while (queryRun.next())
{
totalRecords++;
}
}
info(strFmt(“Total Records : %1”, totalRecords));
}
Subscribe to:
Posts (Atom)
Best Practices for Troubleshooting Application Issues in D365 and Power Platform
When facing application issues, it’s important to systematically troubleshoot before reaching out for support. Follow these steps to ensure...
-
You may face this error when importing data through data entities and this mostly because of the index of the staging table. The data in you...
-
Microsoft Dynamics Ax Macros In MorphX macros are not commonly used. A few places make use of macros such as keeping track of the li...