Get day, month and year from date in axapta x++

In Dynamics AX, sometimes we need to get the day, month or year from a date and we don't know how to do this... but we can do this easily...

//Get day from date

//Get month from date

//Get year from date

Passing Parameters to a Report in Dynamics AX « Rehan Aqeel's Blog

Passing Parameters to a Report in Dynamics AX « Rehan Aqeel's Blog:

Creating reports in AX is generally ‘a walk in the park’ even for the new developers not fully acquaint with the syntax of X++. However, it sometimes becomes challenging to understand how the parameters could be passed to a report when you want to initiate that report from a form.

Let’s look at an example where you may want to create a ‘Purchase Requisition Report’ that the users could generate to see the status of each purchase requisition and the associated workflow entries for that Purchase Requisition.
I will not go into the details of how to develop this report, but you should know that such a report do not exist in the out-of-the-box functionality within AX 2009.
So let’s say that you have developed this report and now when you generate this report you can pass on the required ‘Purchase Requisition ID’ in the ‘Parameter Prompt’ of the report to view the particular PR details accordingly.
However, now in the next step you want to call this report from the ‘Purchase Requisition Form’ (i.e PurchReqTable). To do this, you should first create a ‘Button’ within the ButtonGroup on the form.
Now right-click on the ‘Methods’ node within the newly created button and choose ‘Override Method –> clicked’
Within the clicked function, you should write the following code;
void clicked()
Args args = new args();
ReportRun reportRun;
reportRun = classFactory.reportRunClass(args);
The above code calls the args() system class. This class is used to pass arguments to a class-constructor. You can pass information such as name, caller, and parameters to a new class. This code passes the relevant Purchase Requisition ID (which is currently selected by the user on the form) to the report ‘PurchRequisitionDetails’ in the above code.
Now, you need to go to the report (which in this case is PurchRequisitionDetails). Right-Click on the methods node of the Report and click on ‘Override Method –> init’
In this init method, you need to enter the following code to allow the report to read the parameters from the form.
public void init()
.addRange(fieldnum(PurchReqTable, PurchReqId)).value(element.args().parm());
info(“Error in init method”);
Once you have got the above code correctly entered, you should now be able to generate your report directly from the form.

Joining Data Sources on Forms

Joining Data Sources on Forms

Data sources can be joined together in the following ways:

  • Display data from more than one table, as if it is a single data source.

    For example, fields from more than one table might be displayed in a single grid.

    With this type of join, the two data sources, in many respects, function as a single data source. For example, if you use an inner join and if a user is modifying or adding data to a record in a grid, neither table will be updated until the whole "record" (grid row) is exited rather than a table being updated as the user moves from one data source to another within the row.

  • Display data from more than one table where there is a parent/child relationship between the data sources. The two data sources are kept visually separate.

    For example, order records might be displayed as the parent data source in one grid and order lines as the child data source in another grid.


For more information about joining data sources, see the tutorial_Form_Join form.

  1. Add both data sources to the Data Sources node in the form.

  2. Set the JoinSource property on the secondary data source to the name of the main data source.

  3. Set the LinkType property on the secondary data source to InnerJoin, OuterJoin, ExistJoin, or NotExistJoin.

    The LinkType property settings are described later in this topic.

  4. Create the form design, and then display the relevant fields from the form data sources. Typically, you would choose a grid control for your joined data sources.


You also need to write code to update data in shared fields. For example, if there is a relationship between the tables on Table1.Field1 and Table2.Field2, only one of these fields will be displayed in the form (because the fields are identical). When a change is made to Table1.Field1 on the form, however, Table2.Field2 is not automatically updated. You must add code to the form—for example, on the modified method for Table.Field1.

Advantages of Joining Data Sources

It is also possible to display data from other data sources by using the display or edit methods. Following are the advantages to joining data sources:

  • Performance is increased if you join data sources, compared to using the display or edit methods. Selects, inserts, and updates can occur simultaneously in more than one table because a single query is used.

  • Navigation is synchronized in both data sources—when the user selects a new record, both data sources are updated at the same time.

  • Notification methods, such as active, are run for both data sources. Methods that operate on the data source, such as next, executeQuery, and so on, are redirected to the data source that owns the join, the main data source. The init method is run for both and/or all data sources.

Display data from more than one table where there is a parent/child relationship between the data sources, and the two data sources are kept visually separate.

  1. Add both data sources to the Data Sources node in the form.

  2. Set the JoinSource property on the child data source to the parent data source.

  3. Set the LinkType property on the child data source to Active, Passive, or Delayed.

    The LinkType property controls how the child data source is updated in relation to changes in the master data source.

  4. Create the form design, and then display the relevant fields from the form data sources. Typically, you would choose two grid controls—one to display the parent data source and one to display the child data source.

The following table describes the different settings for the LinkType property.

Use Passive, Delayed, and Active when you join data sources that have a parent/child relationship, and InnerJoin, OuterJoin, ExistJoin, and NotExistJoin should be used when joining data sources to appear as one data source.


How the join is performed


Linked child data sources are not updated automatically. Updates of the child data source must be programmed on the active method of the master data source.


A pause is inserted before linked child data sources are updated. This enables faster navigation in the parent data source because the records from child data sources are not updated immediately. For example, the user could be scrolling past several orders without immediately seeing each order lines.


The child data source is updated immediately when a new record in the parent data source is selected. Continuous updates consume lots of resources.


Selects records from the main table that have matching records in the joined table and vice versa.

There is one record for each match. Records without related records in the other data source are eliminated from the result.


Selects records from the main table whether they have matching records in the joined table.


Selects a record from the main table for each matching record in the joined table.

The differences between InnerJoin and ExistJoin are as follows:

  • When the join type is ExistJoin, the search ends after the first match has been found.

  • When the join type is InnerJoin, all matching records are searched for.


Select records from the main table that do not have a match in the joined table.

Creating a new Number Sequence for an Existing Module, and Putting it to Use!

Imparted from here

Creating a new Number Sequence for an Existing Module, and Putting it to Use!

When I first learned how to create a Number Sequence in my Dynamics AX 2009 Development IV Class (80014) in February of 2010, I left with more confusion about the topic than it should have, and I dreaded coming back to work with the prospect of actually having to implement new Number Sequences. However, once I pulled together the precise steps from various books, online documents, and flat out trial-and-error, the task turned out to not be quite as bad as I had originally left the class thinking. I was however dumbfounded as to why no single source (that I was able to find) outlined the exact steps from creating a new Number Sequence to putting it to use in one clean tutorial.

NOTE: Please bear with me in this tutorial; I am going to break naming convention best practices, so that my example is clearer.

The first thing you need to do is determine which module you want/need to create the new number sequence for. For this example, I am going create a new number sequence for the “Accounts Receivable” module. Then take the following steps:

Creating a new Number Sequence for the Accounts Receivable Module

1. Create your Extended Data Type that will be used in your table as your Number Sequence field. For this example we will create a string based Extended Data Typecalled edt_ComplaintId (with a Label property = “Complaint Report”)

2. Next, since we are using the “Accounts Receivable” module, we must modify the proper NumberSeqReference_XXXX Class. Accounts Receivable, actually maps to Customer (or Cust), so we need to make a modification to theNumberSeqReference_Customer class.
We are only concerned with the loadModule() method, and will simply need to add the following code to it:

numRef.dataTypeId = typeId2ExtendedTypeId(typeid(edt_ComplaintId)); numRef.referenceHelp = "Unique key for the Complaint Report"; numRef.wizardContinuous = true;
numRef.wizardManual = NoYes::No;
numRef.wizardAllowChangeDown = NoYes::No;
numRef.wizardAllowChangeUp = NoYes::No;
numRef.wizardHighest = 999999;
3. After compiling and saving your changes, the next step is to use the Number Sequence Wizard to set it up. Click Basic > Setup > Number sequences >Number sequences to open the form where you can manage your Number Sequences.

4. Click on the “Wizardbutton, which then should initialize the wizard.

NOTE: If you receive an error at this point telling you “The application already has the required number sequences”, this means that you either did not add the definition to an established NumberSeqReference_XXXX Class' (in this example, the NumberSeqReference_Customer Class)loadModule() method, or you have already run the Wizard and set it up.
5. Once you arrive on the Wizard Welcome screen, click the Next > button.

6. On the following screen, verify that the Module is “Accounts receivable” and theReference is “Complaint Report” (which is the label of our Extended Data Type). TheNumber Sequence code is just an auto-generated value that you can leave as is (Remember this code, so that you can find it in your list of Number Sequences, because you are going to want to make a couple changes to it). Once you have verified the above, click the Next > button.

7. The next screen just gives you an overview, click the Finish button.

8. You should then see your Number Sequence in the list.

9. You will probably want to change the Format to something such as “CR-######”

10. At this point, your Number Sequence is ready for use!

Using the Number Sequence

1. Create a Table and name it tbl_Complaint.

2. Add the edt_ComplaintId Extended Data Type as one of the fields (drag and drop the Extended Data Type directly into the fields of the Table) and name this field ComplaintId.

3. Add the following Method to the tbl_Complaint:

static client server NumberSequenceReference numRefComplaintId()
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(edt_ComplaintId)));
4. Create a Form called frm_Complaint.

5. Add the tbl_Complaint table to the form’s Data Sources, and name the Data Source ds_Complaint.

6. Add the following Methods to the Form:

public class FormRun extends ObjectRun
NumberSeqFormHandler numberSeqFormHandler;

NumberSeqFormHandler numberSeqFormHandler()
if (!numberSeqFormHandler)
numberSeqFormHandler = NumberSeqFormHandler::newForm(Tmt_CallReport::numRefComplaintId().NumberSequence, element, ds_Complaint.dataSource(), fieldnum(tbl_Complaint, ComplaintId));
return numberSeqFormHandler;
7. Add the following Methods to the ds_Complaint Data Source:

public void create(boolean _append = false)

public void delete()

public void write()
8. Your Number Sequence should now function!