Skip to main content

ExecuteQuery code

ExecuteQuery code:


public void executeQuery()
{
    ;
    TECPOGroupHeader_ds.query().dataSourceTable(tableNum(TECPOGroupHeader)).clearRanges();
    if(statusFilter.valueStr() == enum2str(TEC_AllDraftPosted::Draft))
        TECPOGroupHeader_ds.query().dataSourceTable(tableNum(TECPOGroupHeader)).addRange(fieldnum(TECPOGroupHeader,Status)).value(sysquery::value(TECPOGroupStatus::Draft));
    if(statusFilter.valueStr() == enum2str(TEC_AllDraftPosted::Posted))
        TECPOGroupHeader_ds.query().dataSourceTable(tableNum(TECPOGroupHeader)).addRange(fieldnum(TECPOGroupHeader,Status)).value(sysquery::value(TECPOGroupStatus::Posted));
    //add by fanddy
    if(statusFilter.valueStr() == enum2str(TEC_AllDraftPosted::Confirmed))
        TECPOGroupHeader_ds.query().dataSourceTable(tableNum(TECPOGroupHeader)).addRange(fieldnum(TECPOGroupHeader,Status)).value(sysquery::value(TECPOGroupStatus::Confirmed));
    //END add by fanddy
    if(CreatorFilter.value() == true)
        TECPOGroupHeader_ds.query().dataSourceTable(tableNum(TECPOGroupHeader)).addRange(fieldnum(TECPOGroupHeader,CreatedBy)).value(sysquery::value(curUserId()));
    super();

CusTable_ds.query().dataSourceNo(1).sortClear();
CusTable_ds.query().dataSourceNo(1).addSortField(fieldNum(CustTable, AccountNum), SortOrder::Ascending); CusTable_ds.executeQuery();


}


Sorting records

Sorting is the most important thing when display the data to the user. The user mostly prefers sorting functionality in the grid forms. AX 2012 has inbuilt functionality to sort the records in the grid by simply clicking the header of the grid column. Multiple sorting is not supported in the AX 2012. For example sort the fields by class and student name. Only single field sorting functionality is working in AX 2012.
As per the below example, we need to sort the record by student name. So, we should add some code in the form datasource init methd like below.
public void init()
{
    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, StudentName), SortOrder::Ascending);
}
We can also clear the sorting functionality by calling the form datasource sortClear method like below.
void clicked()
{
    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();
    Hari_ExamResult_ds.executeQuery();
    super();
}
We should call the form datasource execute query to reflect the changes.
We can change the sorting field by using the below code.
First, clear the existing sorting field then add new sorting field.
void clicked()
{
    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();
    Hari_ExamResult_ds.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, Standard), SortOrder::Ascending);
    Hari_ExamResult_ds.executeQuery();
    super();
}
We can use this code logic to achieve some sorting related business requirement


Comments

Popular posts from this blog

Number sequence with existing module and new module

Number sequence customization in Dynamics 365 Create a number sequence in a standard module Step 1: Create new EDT Step 2: Add a new code block to the loadModule in the NumberSeqModuleXXX class Step 3: Add a new static method to the parameters table of the module to get the number sequence reference Using Extension [ExtensionOf(classStr(NumberSeqModuleCustomer))] final class NumberSeqModuleCustTest_Extension { protected void loadModule() { NumberSeqDatatype datatype = NumberSeqDatatype::construct(); next loadModule(); datatype.parmDatatypeId(extendedTypeNum(TestId)); datatype.parmReferenceHelp(literalStr(‘Test ID’)); datatype.parmWizardIsContinuous(false); datatype.parmWizardIsManual(NoYes::No); datatype.parmWizardIsChangeDownAllowed(NoYes::No); datatype.parmWizardIsChangeUpAllowed(NoYes::No); datatype.parmSortField(1); datatype.addParameterType(NumberSeqParameterType::DataArea, true, false); this.create(datatype); } } [ExtensionOf(tableStr(CustParameters...

[D365/AX7] How to: Create and Use number sequence

[D365/AX7] How to: Create number sequence Posted on January 7, 2018 Updated on January 11, 2018 Number sequences are used to generate readable, unique identifiers for master data records and transaction records that require identifiers. A master data record or transaction record that requires an identifier is referred to as a reference. On this example, we are going to create a new number sequence for customer group. Create a new class that extends the NumberSeqModuleCustomer class and then create the method loadModule_Extension and add the following code: class NumberSeqModuleCustomer_CFS extends NumberSeqModuleCustomer {         public void loadModule_Extension()         {                 NumberSeqDatatype datatype = NumberSeqDatatype::construct();          ...

CREATE AND POSTING PURCHASE ORDER THROUGH X++ IN AX 2012 DYNAMICS AX

CREATE AND POSTING PURCHASE ORDER THROUGH X++ IN AX 2012 DYNAMICS AX   static void PurchOrderCreate(Args _args)   { NumberSeq numberSeq; PurchTable purchTable; PurchLine purchLine; ttsBegin; numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId()); numberSeq.used(); purchTable.PurchId = numberSeq.num(); purchTable.initValue(); purchTable.initFromVendTable(VendTable::find('1001')); if (!purchTable.validateWrite()) { throw Exception::Error; } purchTable.insert(); purchLine.PurchId = purchTable.PurchId; purchLine.ItemId = '1205'; purchLine.createLine(true, true, true, true, true, true); ttsCommit; info(strFmt( "Purchase order '%1' has been created", purchTable.PurchId)); } .............................................. static void PurchOrderPost(Args _args) { PurchFormLetter purchFormLetter; PurchTable purchTable; purchTable = PurchTable::find('000409'); purchFormLetter = PurchFormLetter::construct( D...