Project Item Journal D365FO


Project Item Journal D365FO

Dynamics technical consultants often times receive the requirements to create the journal using X++ where we couldn't use data entity for any reason.

So, In this article, I am writing the sample which may help you a lot to create a project Item journal easily.





public void createProjectInventJournal(ProjectJournalContract    _projectJournal)
    {
        InventDim                            inventDim;
        InventJournalName                    InventJournalName;
        InventJournalTable                   inventJournalTable;
        InventJournalTableData               journalTableData = JournalTableData::newTable(inventJournalTable);
        InventTable                          inventTable;
        ProjTable                               projTable;
        AWCFieldServIntegrtionMainAccount     ServiceOffsetAccount=this.findServiceMainAccount(AWCFieldServiceIntegrationType::ProjectItem);
       
         ProjectJournalTransContract  journalTransContract;

        if(_projectJournal.getProjectJournalTransCount()==0)
        {
            return;
        }
       

        journalTransContract = _projectJournal.getProjectJournalTrans(0);

        select projTable
            where projTable.ProjId==journalTransContract.ProjectId;

        select inventTable
            where inventTable.itemId==journalTransContract.ItemId;

        select InventJournalName
            where InventJournalName.JournalType==InventJournalType::project
        && InventJournalName.isFSJournal==NoYes::Yes;

        inventJournalTable.JournalId = journalTableData.nextJournalId();
        inventJournalTable.JournalType=InventJournalType::project;
      
        journalTableData.initFromJournalName(InventJournalName);
     
        inventJournalTable.insert();

        InventJournalTrans          inventJournalTrans;
        InventJournalTransData      journalTransData = journalTableData.journalStatic().newJournalTransData(inventJournalTrans, journalTableData);
        journalTransData.initFromJournalTable();

        inventJournalTrans.TransDate    = today();

       

        inventJournalTrans.ProjId               =journalTransContract.ProjectId;
       inventJournalTrans.ProjCategoryId       = journalTransContract.ProjectCateId;
        inventJournalTrans.initFromProjTable(projTable);

        inventJournalTrans.initFromInventTable(inventTable);
       
        inventJournalTrans.Qty              = journalTransContract.QtyUsed;
        inventJournalTrans.PriceUnit        = journalTransContract.CostPrice;
     
        inventJournalTrans.ProjUnitID       = journalTransContract.Unit;
        inventJournalTrans.Worker           = HcmWorkerLookup::currentWorker();
        inventJournalTrans.LedgerDimension  = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(ServiceOffsetAccount.MainAccountId).RecId);
        inventJournalTrans.activityNumberModified();
        inventDim.clear();
        inventDim.InventSiteId  = journalTransContract.Site;
        inventDim.InventLocationId =journalTransContract.Location;
        inventDim.wMSLocationId = journalTransContract.Warehouse;

       
        inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;

        //other fields
        journalTransData.create();
    }

Currency Conversion X++ AX7, D365FO and AX-2012


Currency Conversion X++ AX7, D365FO and AX-2012


Convert currency to currency.


Static void main(Args args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    AmountMst amountMST;
    CurrencyCode toCurrency =  ‘AED’;
    CurrencyCode FromCurrency =  ‘USD’;

    AmountCur amountCur = 5000;



        currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
        amountMST =  currencyExchangeHelper.calculateCurrencyToCurrency(toCurrency, fromCurrency,amountCur,true);

  
info(strFmt(“%1”, amountMST))


}



Convert Transaction currency to company ledger currency.
The method will convert the transaction currency into accounting currency defined in the ledger.

static void Main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘EUR’;
    AmountCur amountCur = 5500.00;
    AmountMst amountMST;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
    amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
    info(strFmt(‘%1’,amountMST));
}





Convert Company currency to transaction currency.

The method calculates the transaction currency amount from an accounting currency given.

static void  main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘AED’;
    AmountCur amountCur;
    AmountMst amountMST = 5500.00;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea("DUM").RecId), systemDateGet());
    amountCur = currencyExchangeHelper.calculateAccountingToTransaction(transCurrency, amountMST ,true);
    info(strFmt(‘%1’,amountcur));
}

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...