Showing posts with label AX7. Show all posts
Showing posts with label AX7. Show all posts

Activate Financial Dimensions in Dynamics 365FO

 

Activate Financial Dimensions 
How to resolve the error when activating financial dimension in D365 FO – “The activation of dimensions is only allowed when the system is in maintenance mode. Maintenance mode can be enabled in this environment by running maintenance jobs from LCS or using the Deployment Setup tool locally.


So to fix this issue or to activate the financial dimension, you need to enable the maintenance mode on your targeted environment. only then you can activate the Financial Dimension.
There are 3 ways to enable maintenance mode.
  • LCS
  • Command Line
  • Query
LCS
Login to LCS, Navigate to your environment, Go to Maintain menu and click on enable maintenance mode.


Command Line
Open the command windows as Systems Administrator and execute the below command.
K:\AOSService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.AX.Deployment.Setup.exe –metadatadir K:\AOSService\PackagesLocalDirectory –bindir C:\AOSService\PackagesLocalDirectory –sqlserver . –sqldatabase axdb –sqluser AOSUser –sqlpwd AOSWebSite@123 –setupmode maintenancemode –isinmaintenancemode true
SQL Script
Please perform the following steps 
  • Disable the IIS services.
  • Disable the Batch job services
  • Open SQL and Execute the below command on AxDB
Update SQLSystemvariables set Value=0 where parm='CONFIGURATIONMODE'

Support Faryal's Cusine


Customer Cancel Payment Transaction



Customer Cancel Payment Transaction 

Oftentimes Technical consultants receive the requirement to write some logic or feature where we can cancel the X number of payments by selecting many records at once.


class TMV_CustomerPaymentCancel
{

   

    public static void main(Args _args)
    {
        LedgerJournalTrans _ledgerJournalTrans;
        TMV_CustomerPaymentCancel objCancelPayment=new TMV_CustomerPaymentCancel();
        objCancelPayment.cancelpaymentExecution('R00007404',_ledgerJournalTrans);
    }

    public void cancelpaymentExecution(InvoiceId _invoiceid,LedgerJournalTrans _ledgerJournalTrans)
    {

        CustTrans custTransOffset;
       
        ReasonTable reasonTable;
        ReasonCode reasonCode;
        ReasonRefRecID reasonRefRecID;
     
        Args args;
 
        ;
        custTransOffset= this.findPaymentReference(_invoiceid);
        if(custTransOffset.RecId>0)
        {
            this.CancelPayment(custTransOffset, _ledgerJournalTrans);
        }

    }

    public CustTrans findPaymentReference(InvoiceId _invoiceid)
    {
        CustTrans custTrans,custTransOffset;

        custTrans = CustTrans::findFromInvoice(_invoiceid);
        select custTransOffset
            where custTransOffset.OffsetRecid==custTrans.RecId
            && custTransOffset.TransType==LedgerTransType::Payment;
        return custTransOffset;
    }

    public void CancelPayment(CustTrans custTransOffset,LedgerJournalTrans _ledgerJournalTrans)
    {
        CustVendPDCManager  custVendPDCManager;
        BankPaymCancel bankPaymCancel;
        Args    localArgs;
        if(custTransOffset.RecId)
        {
 
            infolog.clear();
            try
            {
                localArgs = new Args();

                bankPaymCancel = BankPaymCancel::newBankPaymCancel(custTransOffset);

                //  bankPaymCancel.parmReason(reasonTable.Reason);
                //   bankPaymCancel.parmReasonComment(reasonTable.Description);
                bankPaymCancel.parmTransDate(systemDateGet());
       
                localArgs.caller(bankPaymCancel);
                localArgs.record(custTransOffset);
                BankPaymCancel::serverRun(localArgs);
 
            }
            catch
            {
               


            }
           
        }
    }



    public  str getErrorStr()
    {
        SysInfologEnumerator enumerator;
        SysInfologMessageStruct msgStruct;
        Exception exception;
        str error;
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            error = strfmt("%1 %2", error, msgStruct.message());
        }
        return error;
    }

}

Support Faryal's Cusine


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));
}

Support Faryal's Cusine


Project Journal D365FO


Project-Hour Journal D365FO


By using the following code sample, You can create the Project journal easily.



  public void createProjectHourJournal(ProjectJournalContract    _projectJournal) // project hour journal
    {
        ProjJournalTableData    JournalTableData;
        ProjJournalTransData    journalTransData;
        ProjJournalTable        journalTable, journalTableUpdate;
        ProjJournalTrans        journalTrans;
        ProjTable               projTable;
        ProjInvoiceTable        projInvoiceTable;
        NumberSeq               numberSeq;
        ProjJournalCheckPost    jourPost;
        ProjQtyEmpl             qty;
        JournalNumOfLines       numOfLines;
        ProjCategory            projCategory;
        LedgerJournalName       ledgerJournalName;
        ProjectJournalTransContract     projecJournalTrans;
       // ProjLinePropertySetup       projLinePropertySetup;
        ProjJournalName         projJournalName;

        if(_projectJournal!=null)
        {

            select projJournalName
                where projJournalName.isFSJournal==NoYes::Yes;

            projecJournalTrans=_projectJournal.getProjectJournalTrans(0);
           
            ttsBegin;
            journalTableData =          JournalTableData::newTable(journalTable);


            journalTransData =            journalTableData.journalStatic().newJournalTransData(journalTrans,  journalTableData);


            //select projLinePropertySetup
            //    where projLinePropertySetup.ProjCode==TableGroupAll::All
            //    && projLinePropertySetup.ProjRelation==projTable.ProjId;

            projTable           = ProjTable::find(projecJournalTrans.ProjectId);
            // Init        JournalTable
            projCategory=ProjCategory::find(projecJournalTrans.ProjectCateId);
      
            journalTable.JournalId      = journalTableData.nextJournalId();

            journalTable.JournalType    = ProjJournalType::Hour;

            journalTable.ProjId=projecJournalTrans.ProjectId;
            journalTable.ProjQty=projecJournalTrans.QtyUsed;
            journalTable.CategoryId=projecJournalTrans.ProjectCateId;
            journalTable.ProjTransDate=systemDateGet();
            //journalTable.LinePropertyId
            journalTable.initFromProjJournalName(projJournalName);
            journalTable.insert();

          
            journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));

            journalTrans.clear();
            journalTransData.initFromJournalTable();
    
            projInvoiceTable    = projTable.projInvoice();
           
          

            journalTrans.setTransDate();
          //  journalTrans.TransDate      = systemDateGet();
            journalTrans.ProjTransDate  = systemDateGet();
            journalTrans.ProjId         = projTable.ProjId;
            journalTrans.Qty            = projecJournalTrans.QtyUsed;
            journalTrans.CategoryId     = projCategory.CategoryId;
         //   journalTrans.LinePropertyId = projLinePropertySetup.LinePropertyId;
            journalTrans.Worker         = HcmWorkerLookup::currentWorker();
            journalTrans.ActivityNumber = projecJournalTrans.ActivityId;
            journalTrans.Txt            = _projectJournal.FreeTxt;

           
           

            if(projInvoiceTable.CurrencyId)
            {
                journalTrans.CurrencyId =            projInvoiceTable.CurrencyId;
            }

            else
            {
                journalTrans.CurrencyId =           Ledger::accountingCurrency(CompanyInfo::current());

            }


            journalTrans.DefaultDimension   = projTable.DefaultDimension;
            journalTrans.TaxGroupId         =           ProjParameters::taxGroupInvoice(projTable.ProjId);

            if  (journalTrans.Worker)
            {
                journalTrans.setHourPrices();
                journalTrans.setPeriodDate();
            }

            numberSeq =            NumberSeq::newGetVoucherFromId(journalTable.VoucherNumberSequenceTable, false);
            journalTrans.Voucher        = numberSeq.voucher();
            journalTransData.create();

            ttsCommit;
       

        }

    }

Support Faryal's Cusine


Compnay Currency X++



Company Currency X++



You can find the company Currency using below Code.

CompanyInfo::standardCurrency() 
Ledger::accountingCurrency(CompanyInfo::current()

info(strFmt("%1",CompanyInfo::standardCurrency() ));

info(strFmt("%1",Ledger::accountingCurrency(CompanyInfo::current())));

Support Faryal's Cusine


Ledger Dimension D365FO



Ledger Dimension AX2012 & D365FO



In AX -2012 We use DimensionStorage class and method getDynamicAccount to get the Ledger dimension of the following accounts.

For Instance 
DimensionStorage::getDynamicAccount("ABC",LedgerJournalACType::Ledger);
  1. Ledger
  2. Cust
  3. Vend
  4. Project
  5. FixedAssets
  6. Bank
In D365FO  DimensionStorage is removed and the new class introduces LedgerDynamicAccountHelper to get the Ledger dimension of the following accounts.

For Instance 


LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber("Project-001",LedgerJournalACType::Project);


Support Faryal's Cusine


Compare Records D365FO & AX 2012





How to compare two records buffer field to field. 



public static container compareRecords(Common _record1, Common _record2)
{
    SysDictTable    dictTable = new SysDictTable(_record1.TableId);
    SysDictField    dictField;
    FieldId         fieldId, extFieldId;
    container       ret;
    int             i, j;
    ;

    if (_record1.TableId != _record2.TableId)
        return conNull();

    for (i=1; i<=dictTable.fieldCnt(); ++i)
    {
        fieldId = dictTable.fieldCnt2Id(i);
        dictField = new SysDictField(_record1.tableId, fieldId);

        if (!dictField.isSystem())
        {
            for (j=1; j<= dictField.arraySize(); ++j)
            {
                extFieldId = fieldId2Ext(fieldId, j);

                if (_record1.(extFieldId) != _record2.(extFieldId))
                {
                    ret += [extFieldId, _record1.(extFieldId), _record2.(extFieldId)];
                }
            }
        }
    }

    return ret;
}




For Demo purpose you can use below code in job/runnable class.


static void demoCompareRecords(Args _args)
{
    VendTable vendTable_1 = VendTable::find('ABC'); 
    VendTable vendTable_2 = VendTable::find('XYZ'); 
 
    container   con;
    int         i;
    ;
 
    con = MyClass::compareRecords(vendTable_1 , vendTable_2 );
 
    for (i=1; i<=conLen(con); i+=3)
    {
        info(strFmt("%1, %2 ,%3"
                   ,fieldId2Name(tableNum(VendTable), conPeek(con, i))
                   ,conPeek(con, i+1)
                   ,conPeek(con, i+2)
                   )
             );
    }
}







Support Faryal's Cusine


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