X++ code to process the multiple selected data from a form with multiple selected helper class

  Requirement :- Create a trade agreement journal with multiple lines. For this you have to create a button called post in custom page form and create multiple lines in that form select all created lines 

and click button upon clicking button the trade agreement journal needs to be created.

Code :-

class BASTradeJournal

{

    public static void main(Args _args)

    {

        // BASTradeAgreementTable tradeAgreementTable = _args.record();

        BASTradeAgreementTable tradeAgreementTable;

        MultiSelectionHelper selectHelper = MultiSelectionHelper::createFromCaller(_args.caller());


        InventDim               inventDim;

        InventTrans             inventTrans;

        InventDimId             inventDimId;

        PriceDiscAdmTable       priceDiscAdmTable;

        PriceDiscAdmTrans       priceDiscAdmTrans;

        PriceDiscAdmCheckPost   priceDiscAdmCheckPost = new PriceDiscAdmCheckPost(false);

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

        try

        {

            // Create Journal number

            ttsbegin;

            priceDiscAdmTable.clear();

            priceDiscAdmTable.initFromPriceDiscAdmName(priceDiscAdmName);

            priceDiscAdmTable.insert();

            ttscommit;

            tradeAgreementTable = selectHelper.getFirst();

            while(tradeAgreementTable)

            {

                // Create Journal line

                ttsbegin;

                priceDiscAdmTrans.clear();

                priceDiscAdmTrans.JournalNum    = priceDiscAdmTable.JournalNum;

                priceDiscAdmTrans.AccountCode   = PriceDiscPartyCodeType::All;

                priceDiscAdmTrans.ItemCode      = PriceDiscProductCodeType::Table;

                priceDiscAdmTrans.ItemRelation  = tradeAgreementTable.ItemId;


                //Fetching inventdimId

                select firstonly inventDimId from inventTrans

                        join inventDim

                        where inventDim.inventDimId == inventTrans.inventDimId

                        && inventDim.InventSiteId == tradeAgreementTable.InventSiteId

                        && inventDim.InventLocationId == tradeAgreementTable.InventLocationId

                        && inventTrans.ItemId == tradeAgreementTable.ItemId;


                priceDiscAdmTrans.LineNum            = 1;

                priceDiscAdmTrans.Currency           = "USD";

                priceDiscAdmTrans.InventDimId        = inventTrans.inventDimId;

                priceDiscAdmTrans.Amount             = tradeAgreementTable.Price;

                priceDiscAdmTrans.UnitId             = tradeAgreementTable.UnitOfMeasureSymbol;

                priceDiscAdmTrans.QuantityAmountFrom = tradeAgreementTable.FromQty;

                priceDiscAdmTrans.PriceUnit          = 1;

                priceDiscAdmTrans.relation           = PriceType::PricePurch;

                priceDiscAdmTrans.FromDate           = tradeAgreementTable.FromTransDate;

                priceDiscAdmTrans.ToDate             = tradeAgreementTable.ToTransDate;

                priceDiscAdmTrans.DisregardLeadTime  = NoYes::Yes;

                priceDiscAdmTrans.insert();

                ttscommit;

                tradeAgreementTable = selectHelper.getNext();

            }


                //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

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