Saturday 20 April 2013

Restrict duplicate records in AX

In case you have a requirement where you are suppose to restrict the duplicate records.

E.g. :


If in case you have 4 fields.
And you require that any two same record values in the four or less columns should not repeat.

You don't want same record(same combination) to be saved twice.



Column:       A            B          C             D
                 amit      60       India          emp
                  yatish       60       India          emp
                 amit         60       India          emp                ****this record should not be saved


Solution :

1) Make new index to the table.
2) Add the fields that you want to be added to the restricting combination.(Here all 4)
3)Go to properties and set 'AllowDuplicates' to "No".

This will restrict you from saving any duplicate combination in the table.

Note: In case you need only A & B column without repeat then add only A & B fields to index.

Delete all transaction data for a specific company in AX

I have noticed that sometimes we might need to delete all the transaction data for a particular company without altering the configuration data.This is possible in AX.

1)Login into AX in the company for which you want to delete the transaction data.
2)Go to AOT.
3)Open class SysDatabaseTransDelete
4)Run it and Click 'YES' to delete all the transaction data in the current logged in company.

This might take few moments depending on the amount of data.

Thursday 14 March 2013

Lookup in AX

This is a small tutorial to setup lookup in ax.


1)Create a new enum - Trix_Enum with 3 enum elements - ele1,ele2 & ele3

2)Create a new EDT  by name : Trix_EDT_Id

3)Create a new table Trix_table with 4 fields :
   Trix_Id[datatype - Trix_EDT_Id]
   Trix_Name[datatype - Name]
   Trix_Type[datatype - Trix_Enum]
   Trix_amount[datatype - AmountMST]


4) Go to AOT> EDT> Trix_EDT_Id
    Expand the relation node and create a Normal relation.
    Go to properties and select the source table in "Table" & source table field in "RelatedField"(E.g.Trix_Id)
    Save the changes.

5)Go to the source table from which data should be lookup.
   Open the AutoLookup field group.
   Add the fields that need to be looked up.(E.g. Trix_Name,Trix_amount)

6)Now use the EDT "Trix_EDT_Id" as edt for any new field.The new field will look up the source         table(Trix_table) columns.(E.g. Here Trix_Id,Trix_Name,Trix_amount)

7)Incase of Related field fixed relation it works as a where clause/condition and should be given on enums.
   Go to AOT> EDT> Trix_EDT_Id
   Expand the relation node and create a Related field fixed relation.
   Go to properties and select the source table field in "RelatedField"(E.g.Trix_Type) & enum value(E.g. 0,1,2) in "Value".
    Note: The condition is ANDed with the normal relation.

Wednesday 13 March 2013

Important functions in AX

Some useful Functions:

curuserid();
Function : Returns the user id of the current user.

curext();
Function : Returns the current logged in company.

today();
Function : Returns machine's current date.

systemdateget();
Function : Returns system application's current date.

System does not support setup 'continuous' of number sequence

Solution:

Some functions need to be called with a transaction processing.So just try using ttsbegin and ttscommit for the fuction call which is issuing the error.
Mostly issued while using the number sequence.

E.g:

ttsbegin;

// statements giving error

ttscommit;

Cannot select a record in (Table_name).Field_name: . The SQL database has issued an error.

Cause:
There is a sync issue with the table on application and the database.

Solution:
Go to   /Administration/ SQL Administration
Select the the table which is giving the error and press the button 'Table actions' > 'Check/Synchronize'.
If this does not fix the issue try 'Index actions' > 'Reindex'

Tuesday 12 March 2013

"Journal has already been posted and, consequently, is not open"

Cause:

The cause of this error is when you are trying to post a Journal which is already posted.This mostly happens when you are trying to post using X++ code.

Check if you are passing new record(LedgerJournalTable) to Class LedgerJournalCheckPost everytime you call it for posting.

First time you call the class the selected record gets posted but second time it is stopped in the validation process.As the record is already posted once.

Bound,Unbound and Calculated Controls

Bound controls:
Bound controls are linked to the table and the information/data is saved(inserted/updated) to the database.Any control which has a datasource and a datafield in its properties is a bound control.

Unbound Controls:
UnBound controls are not linked to the table and information will not be saved(inserted/updated) to the database.
Use unbound controls to display pictures and static text.

Calculated controls:
Calculated method uses a method as the data source.
Usually display and edit methods are used in the data source of such controls.

Box Class

Boxes are mostly used for confirmation from the end user before executing business logic.


There are many Box methods like:
- info, warning, stop, yesNo, OkCancel etc

Class which is used to create Boxes is "Box" and all the methods are static methods in this class.
Box can be useful to beginners who are not used to the Debugger in AX as it can help them trace the path of code execution.

Here is a example job for Box class:
static void Trix_Box(Args _args)
{
    ;
    Box::info("This is an info box");
 
    Box::warning("This is a warning message");
 
    Box::stop("This is stop");
 
    if (Box::yesNo("Would you like to proceed", DialogButton::No, "A box example", "bottom text")
        == DialogButton::Yes)
        {
            info("Processing...");
        }
        else
        {
            throw error ("Process aborted");
        }
     
     
   info ("Process Complete");
}