Monday, 30 May 2016

Inventory Closing through Job

  1. Copy and Paste below code in AOT->Jobs and then run the job.

    Note : Change from and todate in the below job according to your requirement

    Example : If you are doing inventory closing from 1 JAN 2015 to 28 Feb 2015 . 
                     Give same dates in below job.


    static void UpdateInventTransPosting(Args _args)
    {
        InventTransPosting                      inventTransPosting;
        GeneralJournalEntry                     generalJournalEntry;
        GeneralJournalAccountEntry              generalJournalAccountEntry;
        SubledgerVoucherGeneralJournalEntry     subledgerVoucherGeneralJournalEntry;
        TransDate                               frmDt = mkDate(04,05,2015);// Need to change
        TransDate                               toDt = mkDate(15,05,2015);// Need to change
        ;
        startLengthyOperation();
        ttsBegin;
        while select inventTransPosting where inventTransPosting.TransDate <= frmDt && inventTransPosting.TransDate >= toDt
            && inventTransPosting.OffsetLedgerDimension
            && inventTransPosting.InventTransPostingType == InventTransPostingType::Financial
        {
            select LedgerDimension from generalJournalAccountEntry
            join RecId from generalJournalEntry
            where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
            && (generalJournalAccountEntry.PostingType == LedgerPostingType::InventLoss || generalJournalAccountEntry.PostingType == LedgerPostingType::InventProfit)
            join RecId from subledgerVoucherGeneralJournalEntry
            where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
            && subledgerVoucherGeneralJournalEntry.Voucher == inventTransPosting.Voucher
            && subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == inventTransPosting.dataAreaId
            && subledgerVoucherGeneralJournalEntry.AccountingDate == inventTransPosting.TransDate;
           if (generalJournalAccountEntry.LedgerDimension)
            {
                inventTransPosting.selectForUpdate(true);
                inventTransPosting.OffsetLedgerDimension = generalJournalAccountEntry.LedgerDimension;
                inventTransPosting.doUpdate();
            }
        }
        ttsCommit;
        info('Updation completed');
        endLengthyOperation();
    }


Unable to Log on Microsoft Dynamics AX - Error message displayed while generating in the report

Error :

"Unable to Log on to Microsoft Dynamics Ax" error message displayed while generating SSRS reports in Ax 2012



Reason:

BC Proxy(Business Connector )Account does not have proper permissions .

Solution :

Check Report server "Execution Account" . Give same account in system service account place.

Go To System administration->Setup-> system service accounts and  give the BC Execution Account .


How to Change Grid Row Color(Form/List page) in Ax2012

Solution :

Go to Form Datasource and override Displayoption() method and write code according to your requirement.

Example :

 public void displayOption(Common _record, FormRowDisplayOption _options)
{
    SalesTable prodtablelocal;
    
    prodtablelocal = _record;
    
    Switch(prodtablelocal.SalesStatus)
    {
    Case SalesStatus::Delivered:
    _options.backColor(65535); //Light Yellow
    //_options.affectedElementsByControl(Salestable_SalesId.id());
    Break;
    Case SalesStatus::Invoiced:
    _options.backColor(8421631); //Light Red
    //_options.affectedElementsByControl(Salestable_SalesId.id());
    Break;
    Case SalesStatus::Backorder:
    _options.backColor(65408); //Light Green
    //_options.affectedElementsByControl(Salestable_SalesId.id());
    _options.textColor(12582912);
    Break;
    }
}

Settle Vendor Invoice/Payment in Ax 2012

Code:
-----------
static void VendorSettlement(Args _args)
{
VendTable vendTable;
VendTrans invVendTrans, payVendTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
vendTable = VendTable::find("12345");
// Find the oldest unsettled invoice
select firstonly invVendTrans  order by TransDate asc
                            where invVendTrans.AccountNum == vendTable.AccountNum &&
                            invVendTrans.TransType == LedgerTransType::Purch &&
                            !invVendTrans.closed;
// Find the oldest unsettled payment
select firstonly payVendTrans order by TransDate asc
                    where payVendTrans.AccountNum == vendTable.AccountNum &&
                    payVendTrans.TransType == LedgerTransType::Payment &&
                    !payVendTrans.closed;
ttsbegin;
// Create an object of the CustVendTransData class with the invoice transaction as parameter
custVendTransData = CustVendTransData::construct(invVendTrans);
// Mark it for settlement
custVendTransData.markForSettlement(vendTable);
// Create an object of the CustVendTransData class with the payment transaction as parameter
custVendTransData = CustVendTransData::construct(payVendTrans);
//mark it for settlement
custVendTransData.markForSettlement(vendTable);
ttscommit;
// Settle all marked transactions
if(VendTrans::settleTransact(vendTable, null, true,SettleDatePrinc::DaysDate, systemdateget()))
info("Transactions settled");
}

How to Get +1(Tomorrow) days in Dynamics Ax

How to get today's +1 date in Dynamics Axapta?

Solution 

your date variable = DateTimeUtil::date(DateTimeUtil::addDays(DateTimeUtil::getSystemDateTime(), 1));

Get Department Financial Dimension Value

  • To get Department financial dimension value from Journal Transactions (LedgerJournalTrans)
// BP Deviation Documented
public display OMOperatingUnitNumber sha_displayDepartment()
{

    DimensionAttribute                  dimAttribute = DimensionAttribute::findByName('Department'); // Change 'Department' to which dimension you are looking for
    DimensionAttributeValueSetItemView  dimAttributeValueSetItemView;

    select firstOnly dimAttributeValueSetItemView
        where dimAttributeValueSetItemView.DimensionAttributeValueSet == this.DefaultDimension &&
              dimAttributeValueSetItemView.DimensionAttribute == dimAttribute.RecId;
    
    return dimAttributeValueSetItemView.DisplayValue;
}



  • To get Department financial dimension value from Voucher Transactions (GeneralJournalAccountEntry)

 
// BP Deviation Documented
public display OMOperatingUnitNumber sha_displayDepartment()
{
    DimensionAttribute                  dimAttribute = DimensionAttribute::findByName('Department'); // Change 'Department' to which dimension you are looking for
    DimensionAttributeLevelValueAllView dimAttributeLevelValueAllView;
   
   
    select firstOnly dimAttributeLevelValueAllView
        where dimAttributeLevelValueAllView.ValueCombinationRecId == this.LedgerDimension &&
              dimAttributeLevelValueAllView.DimensionAttribute == dimAttribute.RecId;
   
    return dimAttributeLevelValueAllView.DisplayValue;
}