Wednesday, August 30, 2017

Difference between refresh, reread, research() & executeQuery() methods at form data source level

refresh()

Calling refresh This method basically refreshes the data displayed in the form controls with whatever is stored in the form cache for that particular data source record. Calling refresh() method will NOT reread the record from the database. So if changes happened to the record in another process, these will not be shown after executing.

reread()

This method will interact with the data base and runs the query against the data base in order to fetch the new/updated record values. But this will not show the updated values in the form until calling the refresh method. that means it will update the data source form cache only but not existing form control values. So it is better to call the methods as shown here, like reread and after refresh methods in order to fetch the new / updated values from the data base.
formDataSource.reread()
formDataSource.refresh()

research()

Calling research will rerun the existing form query against the database,
therefore updating the list with new/removed records as well as updating
all existing rows. This will even update any existing filters and sorting on
the form,that were set by the user.

research(true)

The research method starting with AX 2009 accepts an optional boolean argument _retainPosition. If you call research(true), the cursor position in the grid will be preserved after the data has been refreshed. This is an extremely useful addition, which solves most of the problems with cursor positioning (findRecord method is the alternative, but this method is very slow).

executeQuery()

Calling executeQuery() will also rerun the query and update/add/delete the rows in the grid. The difference in behavior from research is described below. executeQuery() should be used if you have modified the query in your code and need to refresh the form to display the data based on the updated query.
 formDataSource.queryRun().query() vs formDataSource.query()
An important thing to mention here is that the form has 2 instances of the query object. 0ne is the original datasource query (stored in formDataSource.query()) and the other is the currently used query with any user filters applied (stored in formDataSource.queryRun().query()). When the researchmethod is called, a new instance of the queryRun is created, using the formDataSource.queryRun().query() as the basis. Therefore, if the user has set up some filters on the displayed data, those will be preserved.
This is useful, for example, when multiple users work with a certain form, each user has his own filters set up for displaying only relevant data, and rows get inserted into the underlying table externally (for example, through AIF).
Calling executeQuery, on the other hand, will use the original query as the basis, therefore removing any user filters. This is a distinction that everyone should understand when using research/executeQuery methods in order to prevent possible collisions with the user filters when updating the query.


How to access form objects

Hi All,
Hope you are doing well. here, I am going to post something which is basic and important as well.
• FormRun : element
• DataSource : DataSourceName_ds
• Active Record : DataSourceName
• DataSource Query : DataSourceName_q
• DataSource Query Run : DataSourceName_qr
• Field value : DataSourceName.Field
• Control element.control(element.controlId(formControlStr(FormName, ControlName)))
          Or AutoDeclaration
Till then, Happy Daxing……..

Jumpref in AX 2012

Hi All,
We all know about “View Details” Option in our Ax 2012 Forms and Tables.
Here I wrote one sample for how to get that functionality in our forms or table.
This is done by three ways:
1) By EDT Relations
2) By using JumpRef method
3) By using FormRef property in Table
EDT Relations:
If you use an EDT in tables which have relation with some other table fields, that time you can able to navigate the main table or main form.
FormRef Property:
Select the Table and go to properties and select the required form in the FormRef property.
JumpRef method:
If you are not having that option, simply write an override the JumpRef method in a field of DataSource or in a Form Control. Here I show you a sample jumpRef method code:
public void jumpRef()
{
Args            args;
;
args = new Args();
args = new Args(menuFunction.object());
args.caller(element);
args.record(“RecordName”); // to be a datasource which added in the current form
new MenuFunction(menuitemDisplayStr(“FormName”), MenuItemType::Display).run(args);
}
In the form init() which we called here, we have to check the condition whether the form is called by any dataset or not.
E.g.,
public void jumpRef()
{
Args args = new Args();
SalesTable salesTable;
;
args.caller(this);
salesTable = SalesTable::find(SalesLine.SalesId);
Args.record(salesTable);
new MenuFunction(menuitemdisplaystr(SalesTable), MenuItemType::Display).run(args);
}
Thanks & Happy DaXing….

lookup method in AX 2012

Hi All,
The following is the code for lookup method at control level in form.
public void lookup()
{
//add Query, QueryBuildDataSource, and QueryBuildRange objects. The following code example adds the classes you use to construct the query for the lookup form.
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
//Create an instance of SysTableLookup class. The following code example creates a lookup form for customers. Notice how this in the example represents the current form control.
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(custTable), this);
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupField(fieldNum(CustTable, CustGroup));
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
//Use a query to retrieve data for the lookup form. The following code example uses a range limit so that the lookup form lists customers who have the customer group of 40.
queryBuildRange = queryBuildDataSource.addRange(fieldNum(CustTable, CustGroup));
queryBuildRange.value(’40’);
sysTableLookup.parmQuery(query);
//Use the performFormLookup method to open the lookup form.
sysTableLookup.performFormLookup();
//When you override the lookup method, comment out the call to super. If you do not comment out the call to super, the standard lookup form might appear.
//super();
}
Right-click the form and then click Save. To see the lookup form, right-click the form and then click Open. Find the StringEdit control and then click the arrow to open the lookup form.
Thanks & Happy DaXing……..:)

Top 10 issues discovered from Dynamics AX Code Review

Hope you are doing well. I have great article to spread across Dynamics AX professionals. When I was searching for contents on Table group and Cache lookup properties at Table level, I came across one article published by Bertrand Caillet who has highlighted Top 10 issues discovered from Dynamics AX.
I would suggest to have deep breathe and take some time to examine this article.top-10-issues-discovered-from-dynamics-ax-code-review

Microsoft Dynamics AX Inventory Tables & Classes

The inventDim table is table that holds the combinations of inventory attributes assigned to items at they progress through inventory transactions. For example, an item can be located in many different warehouse, at may different sites, and stored in certain locations. Imagine the number of combinations that can be associated with an items its endless.  Below are the inventory dimensions AX uses to segregate items as they process through the system
InventColorId Item table contains information about colors.
InventSizeId Item table contains information about item size.
ConfigId  table contains information about available configuration of the various items.
InventBatchId table contains information about batches.
InventSerialId table contains information about item serial numbers.
InventLocationId table contains information about warehouses.
InventSiteId table contains information about sites.
wmsLocationId table contains information about locations.
wmsPalletId table contains information about pallets.
The inventTrans table is what I like to call the parent table of all transactions. NO matter what is performed a record will be written to this table when posting occurs. The inventTrans table represents a flow of inventory transactions as data leaves and enters a company for example. If a product is ordered a status field will be set to ordered. If a item is transferred from one warehouse to another warehouse the status will then be set to transfer. The inventory transactions table is typically used for very detailed inventory reports.
InventSum classes are used to find the on-hand information of a certain item at a certain date. The InventOnHand class is used to find the current on-hand information.
InventMovement class validates and prepares data that will be used to generate inventory transactions. All the classes related to the inventMovement class will be prefixed with InvMov
For instance the InvMove_Transfer preps data for inventory transfer journals
The InventUpdate classes are used to insert and update inventory transactions. Whenever a transaction should be posted, the updateNow()method in the correct InventUpdate subclass will execute. The super class in the hierarchy is the InventUpdate class, and the other classes in the hierarchy are prefixed ‘InventUpd_’. For example, InventUpd_Estimated is used whenever an item line is entered in the system that will most likely generate a physical transaction in the future. A good example can be a sales order line that has the on-order sales status. When a line like this is entered or generated in AX, the InventUpd_Estimated is triggered so that the inventory transactions will reflect that the item is on-order can is taken into consideration when the same item is ordered.
Thanks & Happy DaXing…..

How to clear cache for AX 2012 R2 in Windows Server 2012

Hi Experts,
Hope you are cool. I would be focusing on clear cache for AX 2012 R2 in Windows Server 2012.
Please have a glance at the following steps listed below.
1. Close the client or Stop the AOS
2. Press Windows Key + R
3. Enter Command %userprofile% in Run and press enter
4. Unhide the system files
5. Locate the AppData folder
6. The ax_{GUID}.auc file is now written to the AppData folder
7. Delete the .auc file
8. Open the client or Start the AOS.

Note: Please take backup of *.auc and *.kti files before deleting.

Tuesday, August 8, 2017

How to get Mandatory fields on table

The Following Code will let you know the List of Mandatory Fields in a table

static void CheckMandatoryFieldsOnTable(Args _args)
{
        DictTable   dictTable;
        DictField    dictField;
        Counter      i;

        TableId       tableId = tablenum(CustTable);//Table name
      
        dictTable = new DictTable(tableId);
  
        info(strFmt("Total No. of fields in: %1 are: %2\n\n\n",tableId2name(tableId),  dictTable.fieldCnt()));

        info('Mandatory Fields are following');

        for (i=1 ; i<=dictTable.fieldCnt() ; i++)
        {
            dictField = new DictField(tableId, dictTable.fieldCnt2Id(i));
            if (dictField.mandatory())
            {
                info(dictField.name());
            }
        }
}

Friday, August 4, 2017

How to get base enum elements through X++

static void getBaseEnum(Args _args)
{
    EnumId enumId;
    DictEnum dictEnum;
    int            count1;
    Counter  values;
    enumId   = enumNum(MonthsOfYear);
   
    dictEnum = new DictEnum(enumId);
    values = dictEnum.values();
    for(count1=0 ; count1 < values; count1++)
    {
        info(strFmt("%1",dictEnum.index2Label(count1)));
    }
}

get values of base enums using code in x++

Question: How to get  values of base enums using code in x++

static void getEnumValues(Args _args)
{
    EnumId enumId;
    DictEnum dictEnum;
    int      count1;
    String15      enum;
   
    enumId   = enumNum(MonthsOfYear);
    dictEnum = new DictEnum(enumId);
    count1 = dictEnum.values();
    enum = enum2str(MonthsOfYear::June);
    info(strFmt("%1",dictEnum.name2Value(enum)));
}


output:

6

D365 Extensions: Extend the validateField Method on a Table

In this post I will going to show you, how to extend the validateField method on a table. As example I used the SalesLine, where I will ...