Validation on Trade Agreement Journal Line Posting

 Q: How to add Trade agreement Journal Line Posting Validation?

Case Study:

                 In My Case of Trade Agreement at the time of journal line posting check the line in the journal on the basis of six fields relation, ItemRelation, AccountRelation, CurrencyInventSiteId, InventLocationId. First, I have to get the line which record have the highest FromDate in the journal and Iterate in the Journal Table Any Record Field Data match with the above mention field data change the ToDate to one day Previous Date.

Form:


Trade Agreement Journal Lines:

Post Button:

TradeAgreementJournal Form name: PriceDiscAdm

DataSource
1. PriceDiscAdmTrans
2. InventDim
3. EcoResCategory
4. EcoResCategory
5. TmpRetailPriceDiscAdmTrans
6. RetailCategoryContainmentLookup
7. EcoResProductCategory


POST button Controll Name: PriceDiscAdmPost

class: PriceDiscAdmCheckPost

System will validate the below fields

Relation
CN: relation DS: PriceDiscAdmTrans Table: PriceDiscAdmTrans DF: relation

Item Relation
CN: ItemRelation DS: PriceDiscAdmTrans Table: PriceDiscAdmTrans DF: ItemRelation

Account Selection
CN: AccountRelation DS: PriceDiscAdmTrans Table: PriceDiscAdmTrans DF: AccountRelation

Currency
CN: PriceDiscAdmTrans_Currency DS: PriceDiscAdmTrans Table: PriceDiscAdmTrans DF: Currency

Site
CN: InventoryDimension_InventSiteId DS: InventDim Table: InventDim DF: InventSiteId

Warehouse
CN: InventoryDimension_InventLocationId DS: InventDim Table: InventDim DF: InventLocationId


Relation in PriceDiscAdmTrans
PriceDiscAdmTrans.inventDimId == InventDim.inventDimId

Source Code:

[ExtensionOf(classStr(PriceDiscAdmCheckPost))]

final class PriceDiscAdmCheckPost_Extension

{

    void postJournal()

    {

        next postJournal();

        str jornalNum = journalNum;

        PriceDiscAdmTrans           priceDiscAdmTrans,localPriceDiscAdmTrans,delRecordLocalPriceDiscAdmTrans;

        InventDim                   localInventDim,delRecordLocalInventDim;


        while  select * from localPriceDiscAdmTrans 

               order by JournalNum,relation,ItemRelation,AccountRelation,Currency,FromDate desc

               join inventDimId,InventSiteId,InventLocationId from localInventDim

               where localPriceDiscAdmTrans.InventDimId == localInventDim.inventDimId && localPriceDiscAdmTrans.JournalNum == jornalNum

        {

            ttsBegin;

        while select forupdate * From delRecordLocalPriceDiscAdmTrans

              join inventDimId,InventSiteId,InventLocationId from delRecordLocalInventDim

              where delRecordLocalPriceDiscAdmTrans.InventDimId == delRecordLocalInventDim.inventDimId

              && delRecordLocalPriceDiscAdmTrans.relation == localPriceDiscAdmTrans.relation && delRecordLocalPriceDiscAdmTrans.ItemRelation == localPriceDiscAdmTrans.ItemRelation

              && delRecordLocalPriceDiscAdmTrans.AccountRelation == localPriceDiscAdmTrans.AccountRelation && delRecordLocalPriceDiscAdmTrans.Currency == localPriceDiscAdmTrans.Currency

              && delRecordLocalInventDim.InventSiteId == localInventDim.InventSiteId && delRecordLocalInventDim.InventLocationId == localInventDim.InventLocationId

            {

                if(delRecordLocalPriceDiscAdmTrans.FromDate < localPriceDiscAdmTrans.FromDate && delRecordLocalPriceDiscAdmTrans.RecId != localPriceDiscAdmTrans.RecId)

                {

                    delRecordLocalPriceDiscAdmTrans.ToDate = delRecordLocalPriceDiscAdmTrans.ToDate - 1;

                    delRecordLocalPriceDiscAdmTrans.update();

                }

            }

            ttsCommit;

        }

    }


}









Comments

Popular posts from this blog

D365FO – AX – Update Data Entity Target Entity fields with X++

How to Create Auto Lookup Using EDT with Table Reference in D365 F&O