Showing posts with label Journal. Show all posts
Showing posts with label Journal. Show all posts

Wednesday, June 14, 2023

Open journal lines form from the custom form using x++.

 Open journal lines form from the custom form using x++.


  • We need to add ledgerJournalTable in the form data source and don't give any properties.
  • Copy the JournalLines_Review button from the LedgerJournalTable form.

Write the below code in the Form.

public class Form1 extends FormRun
{
    LedgerJournalFormTable  journalFormTable;

    public void init()
    {
        journalFormTable = LedgerJournalFormTable::construct(element);

        journalFormTable.datasourceInitPost(LedgerJournalTable);

        super();
    }

    JournalForm journalForm()
    {
        return journalFormTable;
    }
}


Button clicked method. (copied from LedgerJournalTable)
    [Control("MenuFunctionButton")]
    class JournalLines_Review
    {
        /// <summary>
        /// Handles the Lines->Review button's clicked event.
        /// </summary>
        public void clicked()
        {
            journalFormTable.assertJournalNotInUse();
    
            journalFormTable.parmIsProcessingPaymentOnApprovedJounal(false);
            journalFormTable.parmIsWFApprovedModeSelected(true);
    
            super();
    
            ledgerJournalTable_ds.reread();
        }

    }

The below code I have written in jumpRef method is based on my requirement.

    [Control("String")]
    class Table1_FieldString1
    {
        public void jumpRef()
        {
            super();

            LedgerJournalTable  ledgerJournalTableNew = LedgerJournalTable::find(Table1.FieldString1);


            //ledgerJournalTable_ds.setRecord(ledgerJournalTableNew);

            ledgerJournalTable_ds.findRecord(ledgerJournalTableNew);

            //ledgerJournalTable_ds.reread();
            //ledgerJournalTable_ds.refresh();

            journalFormTable.datasourceInitPost(ledgerJournalTable_ds.cursor());

            JournalLines_Review.clicked();
        }
    }


Another Way:

Keep daxing!!





Tuesday, May 31, 2022

PostAdj Journal in D365FO using x++

Create and post the Adj Journal in D365FO using x++.


private void createPostAdjJournal(ItemId            _itemid,
                                        InventLocationId  _warehouse,
                                        WMSLocationId     _location,
                                        Qty               _qty,
                                        WHSLicensePlateId  _licensePlateId,
                                        InventBatchId     _batch)
    {
        InventJournalTable              inventJournalTable;
        InventJournalTrans              inventJournalTrans;
        InventJournalNameId             inventJournalName;
        InventDim                       inventDim;
        JournalCheckPost                journalCheckPost;
        WHSLicensePlate                 whsLicensePlate;
        InventLocation                  inventLocation;

        ttsbegin;

        whsLicensePlate     = WHSLicensePlate::createLicensePlate(_licensePlateId, true, "");
        inventJournalName   =  InventJournalName::standardJournalName(InventJournalType::LossProfit);

        inventJournalTable.clear();
        inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName));
        inventJournalTable.insert();

        //<Creation of journal Line>
        inventJournalTrans.clear();
        inventJournalTrans.initFromInventJournalTable(inventJournalTable);
        inventJournalTrans.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
        inventJournalTrans.ItemId    = _itemid;
        inventJournalTrans.initFromInventTable(InventTable::find(_itemid));
        inventJournalTrans.Qty       = _qty;

        inventDim.wMSLocationId      = _location;
        inventDim.InventLocationId   = 'ware house';
        inventDim.InventSiteId       = InventLocation::find('ware house').InventSiteId;
        inventDim.InventSizeId       = 'Blank';  //TODO
        inventDim.LicensePlateId     = whsLicensePlate.LicensePlateId;
        inventDim.inventBatchId      = _batch;

        //you can add here as many inventory dimensions as required
        inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
        inventJournalTrans.insert();

        //<Post Journal>
        journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);

        journalCheckPost.runOperation();

        ttscommit;

        info(strFmt('Journal %1 has been posted',inventJournalTable.JournalId));
    }
Keep Daxing!!