X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O

Reuirement : I have to create a table called BASTradeAgreementTable with fields like following

  1. Item number
  2. Product Name
  3. ToDate
  4. FromDate
  5. InventSiteId
  6. InventLocationId
  7. Amount
  8. From
  9. Unit
Step2: After Creating Table I have to create a form and add the created table into the form datasource and add all the fields of that datasource to form grid.

I have to create a button called Post whenever user clicks on that button i have to create and post Trade Agreement Journals with the data provided in the form grid.

[Control("Button")]

    class Post

    {

        /// <summary>

        ///

        /// </summary>

        public void clicked()

        {

            int             recordsCount; 

            BASTradeAgreementTable    tradeAgreement;

            super();

    

            recordsCount = BASTradeAgreementTable_ds.recordsMarked().lastIndex();  // Total number of marked records.

            tradeAgreement = BASTradeAgreementTable_ds.getFirst(1);

  

            InventDim inventDim;

            InventTrans  inventTrans;

          


            // Info(strFmt("%1 - %2 - %3 - %4 -%5 ",tradeAgreement.FromDate,tradeAgreement.ToDate,tradeAgreement.InventSiteId,tradeAgreement.InventLocationId,tradeAgreement.Amount));

            

            PriceDiscAdmTable       priceDiscAdmTable; // for creating Trade agreement journal header

            PriceDiscAdmTrans       priceDiscAdmTrans;  // for creating Trade agreement journal lines

            PriceDiscAdmCheckPost   priceDiscAdmCheckPost = new PriceDiscAdmCheckPost(false);

            PriceDiscAdmName  priceDiscAdmName = PriceDiscAdmName::find('Purch');



            try

            {

                // Create Journal number

                ttsbegin;

                priceDiscAdmTable.clear();

                priceDiscAdmTable.initFromPriceDiscAdmName(priceDiscAdmName);

                priceDiscAdmTable.insert();

                ttscommit;

 

                // Create Journal line

             

                ttsbegin;

                while (tradeAgreement)

                {

                    priceDiscAdmTrans.JournalNum = priceDiscAdmTable.JournalNum;

                    priceDiscAdmTrans.AccountCode = PriceDiscPartyCodeType::Table;

                    //priceDiscAdmTrans.AccountRelation = "001122";

                    priceDiscAdmTrans.ItemCode = PriceDiscProductCodeType::Table;

               

                    priceDiscAdmTrans.ItemRelation = tradeAgreement.ItemId;

                    priceDiscAdmTrans.LineNum = 1;

                    priceDiscAdmTrans.Currency = "USD";


                    InventDimId inventDimId;

                    select inventDimId from inventDim

                join inventTrans where inventTrans.inventDimId == inventDim.inventDimId

                && inventDim.InventSiteId == tradeAgreement.InventSiteId

                && inventDim.InventLocationId == tradeAgreement.InventLocationId

                && inventTrans.ItemId == tradeAgreement.ItemId;


                    priceDiscAdmTrans.InventDimId = inventDim.inventDimId;;

                    priceDiscAdmTrans.Markup = 1150;

                    priceDiscAdmTrans.PriceUnit = 1;

                    priceDiscAdmTrans.Amount=tradeAgreement.Amount;

                    priceDiscAdmTrans.QuantityAmountFrom=tradeAgreement.QuantityAmountFrom;

                    priceDiscAdmTrans.UnitId=tradeAgreement.UnitId;

                    priceDiscAdmTrans.relation = PriceType::PricePurch;

                    priceDiscAdmTrans.FromDate = tradeAgreement.FromDate;

                    priceDiscAdmTrans.ToDate = tradeAgreement.ToDate;

                    priceDiscAdmTrans.insert();

                    tradeAgreement = BASTradeAgreementTable_ds.getNext();

                }

                //     priceDiscAdmTrans.clear();

                ttscommit;

                //Check if journal created

                if(priceDiscAdmTable && priceDiscAdmTrans)

                {

                    Info(strFmt('Created Journal number %1', priceDiscAdmTable.JournalNum));

                    if(!priceDiscAdmCheckPost.checkJournal()) //Determines whether the price and discount agreement journal contains warnings.

                    {

                        priceDiscAdmCheckPost.initJournalNum(priceDiscAdmTrans.JournalNum);

                        priceDiscAdmCheckPost.run(); //Checks and posts the price and discount agreement journal.

                        Info(strFmt('Posted Journal number %1', priceDiscAdmTable.JournalNum));

                    }

                }

            }


            catch(Exception::CLRError)

            {

                error(enum2Str(Exception::CLRError));

            }

        }


    }

Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code