Friday, August 28, 2015

How to find out number of field & field names in the table using X++

static void DictTable(Args _args)
{
dictTable dt;
DictField df;
int numberOfFields;
int fieldId;
int i;
str table;
;

table = 'salestable';
dt = new dictTable(tablename2id(table));
numberOfFields = dt.fieldCnt();
info(strFmt("%1",dt.fieldCnt()));
for (i = 1; i <= (numberOfFields); i++)
{
fieldId = dt.fieldCnt2Id(i);
df = dt.fieldObject(fieldId); //instead of we can use below line.
info(df.label());    

}
 
}

Wednesday, August 26, 2015

Abstract Class and Abstract Method


Abstract Class:

Abstract classes are classes that contain one or more abstract methods.

An abstract method is a method that is declared, but contains no implementation.

When we declare a class as abstract, this class cannot initiate in X++ code. To use this class or its method we have to first extend this class than only we are able to use this class or its method.


This is often used in the standard package for super classes to control that the super class is not declared by mistake. 

The class SalesFormLetter which is used for creating documents such as sales confirmations and sales invoices uses this practice. 

The class has an construct() method which should be used, and to prevent the class being declared using new() 

SalesFormLetter is qualified as abstract.



To understand the abstract class consider following example

We have three classes
     1.      absClass  (it’s an abstract class)
     2.      normalClass (an another class which will use the absClass methods)
     3.      extendAbsClass (this class will extends the absClass)

    1.abstract class absClass
     {
     }

    void printName()
   {
    ;    info("AbsClass... Deepak");
   }


    2. class extendAbsClass extends absClass
       {
        }

    3.class normalClass
      {
      }

  void accessAbsClass()
{
    absClass        absClass;
    extendAbsClass  extendAbsClass;
    ;
 //   absClass = new absClass();    // this declaration will throw error “Object could not be created because class absClass is abstract” so first we extend absClass into extendsAbsClass and further use extendsAbsClass to access absClass methods.
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.printName();
}


Abstract Method:

When we declare a method as abstract, this method should be overload in child class or we can say , this method  should be declare/initiate in child class, than only we can use this class or its method.
Note:
a.      Abstract methods may only be declared in abstract classes.
b.      No code or declarations are allowed in abstract methods.

We have three classes
i.                    absMethodClass
ii.                  extendAbsClass
iii.                NormalClass

1.      abstract class absMethodClass
{
}

abstract void absPrintName()
{
                        // we cannot declare any code in abstract method
}

2.      class extendAbsClass extends absMethodClass
{
}

void absPrintName()
{
    ; // we have to initiate abstract method here as this class extends the abstract class.
    info("abstract method declaration in derived class");
}
3.      class childClass_1
{
}

void accessAbsClass()
{
    extendAbsClass  extendAbsClass;
    ;
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.absPrintName();

}


Conclusion : 

  • Abstract classes can't be instantiated
  • they're explicitly intended to be extended. 
  • They also usually contain abstract methods, i.e. methods without any implementation that must be implemented by any non-abstract child. 
  • It allows you to define high-level concepts and provide some common functionality and leave details for concrete implementations. 


For example, RunBaseBatch class is abstract - it can't be used by itself because it doesn't define any action to run, but you can extend it and inherit a huge amount of functionality common to all batches.

Wednesday, August 12, 2015

Interview Questions

Data dictionary
1.What is an EDT, Base Enum, how can we use array elements of an EDT,
2.Definition and use of Maps, how AddressMap (with methods) is used in standard AX
3.What is the difference between Index and Index hint?
Utility and use of find method.
4.How many types of data validation methods are written on table level?
5.How many types of relations are available in Axapta, Explain each of them.
6.When the recid is generated, what is its utility, what are the different types of Table groups defined on table properties.
7.Difference between Primary & Cluster index.
8.How many kind of lookups can be made and how.
9.How can we utilize field groups in forms
10.How many types of Delete Actions are there in Standard Ax and define the use of each
11.If any record is created in table I want to fetch the date & time stamp, how will you do that
12.What is the function of super()


Classes
1. What is an abstract class, what is the utility of an abstract method
2. Multiple inheritance possible or not, if not how can we overcome that.
3. What is an interface, Why do we implement it
4. Do we need to write main method, give reasons
5. What is difference between new & construct method
6. What is the utilty of the RunOn property
7. What is main class used in batch process OR which class will you inherit to make a batch job
8. How can we make a batch job occur at regular interval
9. What is the main utility of classes in standard Ax
10. Which class is called when we create a SO/PO.
11. What are classes used to write query.
12. What is a static method, why do we make static methods and where can we write it.
13. When do we make methods private or protected.Forms
14. What is the basic structure of a form
15. Utility of init(), run(), wait() methods
16. What are different types of Link Types available in a form datasource, justify each of them
17. Properties of a form datasource
18. validateWrite() method can be written in form datasource as well as table level, when should we write it in form DS and when in table. Similar in case of write() method
19. How can we call table level methods from form DS (similar methods)
20. What is the difference between form init() & DS init()
21. When a form opens what are the sequential methods called.
22. Where is the best place to write code to perform filter in a form
23. What are the different types of menu items available, explain each of them
24. A action type menu item is attached to a form but in the drop down the menu item is not appearing, what could be the problem

Report
1. What are the two most important methods
2. When do block the super() method of fetch
3. Can we make a report from wizard, if yes from where
4. What is a Programmable Section, how we use it in reports
5. What is the difference between Auto Design Spec & Generated Design
6. How can we sort the DS, what facility we can get in by placing fields in Ranges
7. What is the role of executeSection
8. What are Queries, how do we use them

 Menu Items
1. What is the use of Parameter, Enum TypeParameter/Enum Parameter properties of display
2. Why do we provide Configuration key & Security key
3. Normally what do we attach in Output
4. Normally what do we attach in Action

 General Questions
1. What is difference between select & select firstonly statements
2. What are the keywords used to access data from "multiple companies" and "one company to another company".
3. How can we override a lookup
4. How do the following methods work in a form DS.
ds.refresh(), ds.research(), ds.reread(), in what situation we should these methods
5. On closing a form name the methods which are invoked
6. What are security key/configuration keys, how do we use it in Ax
7. How can we provide user level/user group level security
8. What is a virtual company
9. What is Visual MorphXplorer, what do we do with that?(Reverse engineering tool has replaced Visual MorphXplorer)
10. What is the function of Application Hierarchy Tree
11. If you want to monitor the database activity, where can you get that
12. Where can we find the Label log and what is its utility
13. What are the tools you will use to upgrade any object
14. What is the difference between display() and edit() methods, how do we use each
15. What is the use of System Documentation/Application Developer Documentation/Application Documentation

 Few More Questions on DAX
1.What are the classes, Tables, Forms and Methods used to post the sales orders.
2. What are the classes, Tables, Forms and Methods used to post the purchase orders.
3. What are the classes, Tables, Forms and Methods used to post the Ledgers.
4. What are the classes, Tables, Forms and Methods used to post the Inventory.
5. What is the base class to send the on-boad E-mailing.
6. What are the storage Dimensions?
7. What are the Item Dimensions?
8. What is the difference between RunBase and RunBaseBatch?
9. How do you create a NumberSequence for existing Module and also fro new Module.
10.What is the difference between Insert and doinsert.
11.What is the Runbase Stack?


DIFFERENCE BETWEEN SQL AND X++ STATEMENT--
SELECT-
1.Table buffer on the FROM in x++ clause ,not the table as in SQL
2.ORDER BY clause precedes the WHERE clause
3.! for negation ,not NOT as in SQL
4.&& and || for logical operator ,not AND or OR as in SQL.
5.* and ? for like wildcards ,not % and _ as in SQL.

JOIN CLAUSE-

1.Join clause has no ON keyword in x++,use WHERE instead
2.Defauld JOIN direction is left .
3.there are no LEFT and RIGHT keyword for JOIN in x++
4.The FROM clause is optional when:
-No column is listed or
-Only one table is listed in the SELECT in x++

select * FROM CustTable;
select CustTable;

both are same.

OTHERS-
1.The WHILE SELECT statement provides an automatic cursor for return rows in x++
2.There is no HAVING keyword in x++
3.No null values are return in x++

Differrence between RunBase and RunBaseBatch class

RunBase: To create a job or an Action class - a program that carries out processes, such as accepting parameters from the user and then updating records in the database - you use the RunBase framework.
The framework is implemented by the RunBase application class and supplies many features, which include the following:
· Query
· Dialog, with persistence of the last values entered by the user
· Validate

The RunBase application framework runs or batches an operation.

An operation is a unit of work, such as the posting of a sales order or calculation of a master schedule.

The RunBase framework uses the Dialog framework to prompt a user for data input.

It uses the SysLastValue framework to persist usage data and the Operation Progress framework to show operation progress.

The RunBase class is a framework for classes that need a dialog for user interaction and that need the dialog values to be saved per user.

RunBaseBatch:  You can design your own batch job by extending the RunBaseBatch class. You can also write code to schedule the batch to run. The batch runs on the Application Object Server (AOS)

RunBaseBatch is an extension of RunBase - it adds a support for batch processing.

SysOperation framework is a newer framework replacing RunBase (and its extensions such as RunBaseBatch).

It provides better separation of concerns, generation of dialogs from data contracts and quite a few additional features.

class RunBaseBatch extends RunBase implements Batchable

Differences between reread(), refresh(),research()


When working with Forms, commonly after opened the form we need to do some operations with existing data. In few cases we need to interact with data base again and again in order to do. For that we will use these methods. But some times its create confuse what exactly use of these methods, when should we call these methods and why, here is brief info these methods...

refresh() : this method will refresh the data in the data source cache. But it will not interact with the data base to fetch the new/updated record values. What ever values have fetched in the previous query will store in data source cache, this method will just refresh the data source cache only.

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.

executeQuery() is another useful one.  It should be used if you have modified the query in your code and need to refresh the form.  It's like research() except it takes query changes into account.

List page interaction class and methods

Interaction class of list pages extends SysListPageInteractionBase class. Some handful methods of this class are as follows:

 initializing: Called when the form is initializing – Similar to the form init method

 intializeQuery: Also called when the form is initializing – Similar to the datasource init method

 selectionChanged: Called when the active record changes – Similar to the datasource active method.

 setButtonEnabled: Should be overridden to dynamically enable/disable buttons based on the current selection. This is called from the selectionChanged method.

 setButtonVisibility: Should be overridden to show/hide buttons when the form first opens. This is used more to do a one-off layout adjustment based on system configuration/parameters, as well as the menu-item used to open the form. eg If you have a menu-item that opens a form based on status, you may want to hide the relevant ‘status’ field to reduce clutter.

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// ...