Friday, October 8, 2021

Enquiry Form with unbounded fields and get the sum of Amount, Total records from Data source(active records in grid)

AX 2012: Enquiry Form




public class FormRun extends ObjectRun

{

}

public void init()   //Form Init method

{

    AweAdvDefHeader advDefHeaderLoc;

    super();

    AweAdvDefLine_ds.executeQuery();

    select RecId, Asofdate from advDefHeaderLoc order by recid desc;

    AsOfDate.dateValue(advDefHeaderLoc.Asofdate);

    AsOfDate.modified();

}

public void executeQuery()   // DS ExecuteQuery

{

    AweAdvDefHeader advDefHeader;

    Name valueStr, dateStr;

    TransDate valueDate;

    valueStr = AsOfDate.valueStr();

    valueDate = str2Date(valueStr, 213);

    select RecId,Asofdate from advDefHeader where advDefHeader.Asofdate == valueDate;

    if (advDefHeader.RecId )

    {

        this.query().dataSourceTable(tableNum(AweAdvDefLine)).clearRanges();

        this.query().dataSourceTable(tableNum(AweAdvDefLine)).addRange(fieldNum(AweAdvDefLine,AweAdvDefHeader )).value(int642str(advDefHeader.RecId));

        super();

    }    

    //Default values

    PostedAmount.realValue(0.00);

    BilledAmount.realValue(0.00);

    CreditAmount.realValue(0.00);

    AdvDefAmount.realValue(0.00);

    RemaingBalance.realValue(0.00);

    TotalRows.value(0);

}

public void lookup()  // Design -- Field level

{

    Query query = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    QueryBuildRange         queryBuildRange;

    SysTableLookup          sysTableLookup;

    AweAdvDefHeader         AdvDefHeader;

    select firstOnly dataAreaId from AdvDefHeader where AdvDefHeader.dataAreaId == curext();

    sysTableLookup = SysTableLookup::newParameters(tableNum(AweAdvDefHeader), this);

    sysTableLookup.addLookupField(fieldNum(AweAdvDefHeader, Asofdate));

    queryBuildDataSource = query.addDataSource(tableNum(AweAdvDefHeader));

    queryBuildDataSource.addRange(fieldNum(AweAdvDefHeader, Asofdate));

    if (AdvDefHeader.dataAreaId)

    {

       queryBuildDataSource.addRange(fieldNum(AweAdvDefHeader, Asofdate)).value(AdvDefHeader.dataAreaId);

    }

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

    //super();

}

public boolean modified()  // Design -- Field level

{

    Name valueStr;

    TransDate valueDate;

    AweAdvDefHeader advDefHeader;

    boolean ret;

    ret = super();

    AweAdvDefLine_ds.executeQuery();

    valueStr  = AsOfDate.valueStr();

    valueDate = str2Date(valueStr, 213);

    select Asofdate,createdDateTime from advDefHeader

                        where advDefHeader.Asofdate == valueDate;

    CreatedDateTime.dateTimeValue(advDefHeader.createdDateTime);

    return ret;

}

void clicked()  // Button clicked

{

    int             rowcount, countLine;

    Amount          PostedAmt, BilledAmt, CreditAmt, RAmt, AdvDefAmt;

    AweAdvDefLine   advDifLineLoc, advDifLineLocal;

    super();

    advDifLineLoc = AweAdvDefLine_ds.getFirst();

    countLine = 0;

    rowcount = AweAdvDefLine_ds.numberOfRowsLoaded();

    while (advDifLineLoc && rowcount >= countLine)

    {

        select RecId, PostedAmount, Billedamount,CRAmount,RemainingBalance,AdvDefAmount

                     from advDifLineLocal where advDifLineLocal.RecId == advDifLineLoc.RecId;

        PostedAmt +=  advDifLineLocal.PostedAmount;

        BilledAmt +=  advDifLineLocal.Billedamount;

        CreditAmt +=  advDifLineLocal.CRAmount;

        AdvDefAmt +=  advDifLineLocal.AdvDefAmount;

        RAmt      +=  advDifLineLocal.RemainingBalance;

        advDifLineLoc = AweAdvDefLine_ds.getNext();

        countLine++;

    }

    PostedAmount.realValue(PostedAmt);

    BilledAmount.realValue(BilledAmt);

    CreditAmount.realValue(CreditAmt);

    AdvDefAmount.realValue(AdvDefAmt);

    RemaingBalance.realValue(RAmt);

    TotalRows.value(rowcount);

}


No comments:

Post a Comment