Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Monday, December 15, 2014

Create a new record in the opened form

Create a new record in the opened form


We can insert the record by using the below code. This is the normal procedure, creates new table buffer, assign values and call insert method.

void clicked()
{
    Hari_ExamResult  examResults;
    examResults.StudentName = "Zyx";
    examResults.Standard = "Sixth";
    examResults.ExamResult = "Pass";
    examResults.RollNo = 1004;
    examResults.insert();
    super();
}

Our scenario is how to add a new record when form opens. If you use the above code in this scenario we should call the below code after the insert method before the super method call.

    Hari_ExamResult_ds.research();
    Hari_ExamResult_ds.refresh();

Note: Here, form datasource reread method won’t work, because when we call the reread method, it won’t call the form datasource executequery method. But, if we call the research method, it will call the form datasource executequery method.

The best practice for this scenario is calling the form datasource create method.

void clicked()
{
    Hari_ExamResult_ds.create();
    Hari_ExamResult.StudentName = "Zyx";
    Hari_ExamResult.Standard = "Sixth";
    Hari_ExamResult.ExamResult = "Pass";
    Hari_ExamResult.RollNo = 1004;
    Hari_ExamResult.insert();
    Hari_ExamResult_ds.reread();
    Hari_ExamResult_ds.refresh();
    super();

}

Please use the form datasource create method to create the records when form opens.

Tuesday, October 28, 2014

Date range conditions and between operator in AX 2012

I faced some logical issues when I work with the between ranges. So, I just like to share my code logic for your references.

Between operators

AX does not support between operator in select statement. But it is mostly using operator in SQL queries.

For example, find the persons between the age 20 to 30, we can use between operator like below statement

SELECT * FROM Persons WHERE Age BETWEEN 20 AND 30

The above SQL query return the result set that persons between the age 20 and 30.


In AX, we don’t have other options. So, we need to use the basic logic like the below statement

select * from persons where persons.age >= 20 && persons.age <= 30;


Date range:

We can find the date is in the particular date range by using the below statement. For example, if we need to find, what are the courses conducted in the particular date. We can use the below statement.

select * from courses where today() >= courses.startdate && today() <= courses.enddate;


Date ranges overlap:

It is little difficult logic. Find the date range is match with the other date range. For example, find the particular week active employees. (In other words, find the active employee list for the particular week)

select * from employees where employees.validfromdate <= endate && startdate <= employees.validtodate;