Saturday, June 6, 2020

update_recordset in Ax 2012

The X++ SQL statement update_recordset enables you to update multiple rows in a single trip to the server

update_recordset generalJournalAccountEntryUpdateRecSet
                setting
                  TTC_EOMCheckField=NoYes::Yes
                    join generalJournalEntryUpdateRecSet
                        where generalJournalAccountEntryUpdateRecSet.GeneralJournalEntry                           ==  generalJournalEntryUpdateRecSet.RecId
                        &&    generalJournalEntryUpdateRecSet.AccountingDate                                       >=  fromDate
                        &&    generalJournalEntryUpdateRecSet.AccountingDate                                       <=  toDate
                        &&    generalJournalEntryUpdateRecSet.Ledger                                               ==  fromLedger.RecId
                        &&    generalJournalEntryUpdateRecSet.PostingLayer                                         ==  CurrentOperationsTax::Current
                    join DimensionAttributeLevelValueAllViewUpdateRecSet
                        where generalJournalAccountEntryUpdateRecSet.LedgerDimension                               ==  DimensionAttributeLevelValueAllViewUpdateRecSet.ValueCombinationRecId
                        &&    DimensionAttributeLevelValueAllViewUpdateRecSet.DisplayValue                         ==  division
                        &&    DimensionAttributeLevelValueAllViewUpdateRecSet.DimensionAttribute                   ==  DimensionAttribute::findByName("Division").RecId
                    join DimensionAttributeLevelValueAllViewUpdateRecSet2
                        where DimensionAttributeLevelValueAllViewUpdateRecSet2.ValueCombinationRecId               ==  DimensionAttributeLevelValueAllViewUpdateRecSet.ValueCombinationRecId
                        &&    DimensionAttributeLevelValueAllViewUpdateRecSet2.DisplayValue                        ==  selectedMainAccount
                        &&    DimensionAttributeLevelValueAllViewUpdateRecSet2.DimensionAttribute                  ==  DimensionAttribute::findByName("MainAccount").RecId;
        }


Picture of same code with indentation :-

Creating custom lookup in dialog form in Ax 2012

1. write following in class declaration

MainAccount                             mainAccount;





2. Write a new method "accountLookup"

public void accountLookup(FormStringControl _control2)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(mainAccount),_control2);

    sysTableLookup.addLookupField(fieldNum(mainAccount, mainaccountid));
    sysTableLookup.addLookupField(fieldNum(mainAccount, Name));

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

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}







3. now go to "dialog" method and after taking the input for account write the following code

    dialog.addTabPage("Account");
    dialog.addGroup("Account Parameters").columns(2);
    dlgMainAccounts         = dialog.addFieldValue(extendedTypeStr(String255),mainAccounts,"Accounts");
    control2 = dlgMainAccounts.control();
    control2.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(TTC_EOM,accountLookup), this);
    dlgMainAccounts.mcrReplaceOnLookup(false); //this is for entering multiple account values in the field
    controlMainAccounts    = dlgMainAccounts.control();

Applying validation on fields (methods) in dialog form in Ax 2012

1. go to class declaration and make the following "FormBulidStringControl"

FormBuildStringControl                  controlFromDataAreaId,controlToDataAreaId,controlGeneralType,controlMainAccounts,controlDivision;





2. now in the "dialog" method write the following method,below the field where we enter value

controlFromDataAreaId = dlgFromDataAreaId.control();





3. now in the ""dialogPostRun" method write the following code

controlFromDataAreaId.registerOverrideMethod(methodStr(FormStringControl,Validate),
                                            methodStr(TTC_EOM,fromtoEntity_Validate),
                                            this);





4. now make a new method, in this case ""fromtoEntity_Validate

public boolean fromtoEntity_Validate(FormStringControl  _control)
{
    boolean ret         = _control.validate();

    select DataArea from companyInfo
        where companyInfo.DataArea  == _control.valueStr();

    if(companyInfo)
    {
        ret = true;
    }
    else
    {
        ret = ret && checkFailed("Entity does not exist");
    }
    return ret;
}