Welcome to Dynamics Ax blog for learning, sharing and transferring dynamics AX knowledge and all related topics to AX
Get day, month and year from date in axapta x++
//Get day from date
dayOfMth(systemdateget())
//Get month from date
mthOfYr(systemdateget())
//Get year from date
year(systemdateget())"
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.
{
ReportRun reportRun;
;
reportRun = classFactory.reportRunClass(args);
reportRun.init();
reportrun.run();
//hello
}
{
;
try
{
if(element.args().parm())
{
this.query().dataSourceTable(tablenum(PurchReqTable))
.addRange(fieldnum(PurchReqTable, PurchReqId)).value(element.args().parm());
this.query().interactive(false);
super();
}
}
{
info(“Error in init method”);
}
Dynamics AX tools and tutorials: UtcDateTime in Dynamics AX 2009
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.
Tip |
---|
For more information about joining data sources, see the tutorial_Form_Join form. |
Add both data sources to the Data Sources node in the form.
Set the JoinSource property on the secondary data source to the name of the main data source.
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.
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.
Note |
---|
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.
Add both data sources to the Data Sources node in the form.
Set the JoinSource property on the child data source to the parent data source.
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.
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.
Setting | How the join is performed |
---|---|
Passive | 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. |
Delayed | 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. |
Active | The child data source is updated immediately when a new record in the parent data source is selected. Continuous updates consume lots of resources. |
InnerJoin | 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. |
OuterJoin | Selects records from the main table whether they have matching records in the joined table. |
ExistJoin | Selects a record from the main table for each matching record in the joined table. The differences between InnerJoin and ExistJoin are as follows:
|
NotExistJoin | 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!
Creating a new Number Sequence for an Existing Module, and Putting it to Use!
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;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.
numRef.wizardManual = NoYes::No;
numRef.wizardAllowChangeDown = NoYes::No;
numRef.wizardAllowChangeUp = NoYes::No;
numRef.wizardHighest = 999999;
this.create(numRef);
4. Click on the “Wizard” button, 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()4. Create a Form called frm_Complaint.
{
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(edt_ComplaintId)));
}
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 ObjectRun7. Add the following Methods to the ds_Complaint Data Source:
{
NumberSeqFormHandler numberSeqFormHandler;
}
NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
numberSeqFormHandler = NumberSeqFormHandler::newForm(Tmt_CallReport::numRefComplaintId().NumberSequence, element, ds_Complaint.dataSource(), fieldnum(tbl_Complaint, ComplaintId));
}
return numberSeqFormHandler;
}
public void create(boolean _append = false)8. Your Number Sequence should now function!
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
super(_append);
element.numberSeqFormHandler().formMethodDataSourceCreate();
}
public void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}
public void write()
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}