Friday 10 November 2017

How to get customer credit card number based on Expiry date using x++ code


Get customer credit card number based on Expiry date validation 

public static RefRecId getCreditCardOCP(CustAccount    _custAccount)
{
    CreditCardCust custCreditCard;

    select firstOnly RecId,ExpiryDate from custCreditCard
            where custCreditCard.CustAccount == _custAccount;

    if(custCreditCard.ExpiryDate && CreditCard::checkExpireDate(custCreditCard.ExpiryDate))
    {
        return custCreditCard.RecId;
    }

    return 0;

}

Tuesday 7 November 2017

How to get selected query range value using x++ code in Ax 2012 R3

To get selected query range value

In My case need to get selected query range value from existing query.

Conditions

  1. If  range is applied need to filter based on the range 
  2. If  range not applied default it should take system language


    QueryBuildDataSource    qbdsProductTranslation;
    QueryBuildRange         queryBuildRange;
    QueryFilter             queryFilter;
    QueryRun                queryRun;

    qbdsProductTranslation    = _query.dataSourceTable(tableNum(EcoResProductTranslation));
    queryFilter = _query.findQueryFilter(qbdsProductTranslation, fieldStr(EcoResProductTranslation,      LanguageId));

    if(!queryFilter || !queryFilter.value()) //To handle the situation like If languageId is added to Range set to empty and If LanguageId is not added to Range
    {
        queryBuildRange  = qbdsProductTranslation.addRange(fieldNum(EcoResProductTranslation,LanguageId));
        queryBuildRange.value(SystemParameters::getSystemLanguageId());
        queryRun = new QueryRun(_query);
        _query   = queryRun.query();

    }

//setExecutionIdRangesOCP

Thursday 26 October 2017

How Disable Invoice and packing slip button in sales order process for form and list page based on the condition in Ax 2012 R3


SalesTableInteractionHelper  Class

Packing Slip

Method ..\ parmCanPackingslipBeUpdated
public boolean parmCanPackingslipBeUpdated()
{
#GetCached(
        canPackingslipBeUpdated,
        salesTableType.canPackingslipBeUpdated() && !(salesTable.SalesType == SalesType::Sales && salesTable.finalizeStatusOCP() == FinalizeStatusOCP::Open) && !(salesTable.wmsStatusOCP() == NoYes::Yes))
   
}

//info(strFmt("%1 -- %2",canInvoiceBeUpdated,(salesTableType.canInvoiceBeUpdated() && !(salesTable.SalesType == SalesType::Sales && salesTable.finalizeStatusOCP() == FinalizeStatusOCP::Open) && !(salesTable.wmsStatusOCP() == NoYes::Yes))));

Invoice

Method ..\ parmCanInvoiceBeUpdated
public boolean parmCanInvoiceBeUpdated()
{
              
#GetCached(
        canInvoiceBeUpdated,
        salesTableType.canInvoiceBeUpdated() && !(salesTable.SalesType == SalesType::Sales && salesTable.finalizeStatusOCP() == FinalizeStatusOCP::Open) && !(salesTable.wmsStatusOCP() == NoYes::Yes))
   

}

Wednesday 18 October 2017

Table Extension Framework in Ax 2012 R3

Table Extension Framework

http://daxonline.org/9-table-extension-framework.html


Example
To Pack the table

BomReportFinish.updateBOMConsumption();



inventJournalTransExt = inventJournalTrans.inventJournalTransExt();
inventJournalTransExt.SendToWMS = Noyes::Yes;

inventJournalTrans.packInventJournalTransExt(inventJournalTransExt);

line num 91 : journalTransData.insert();





Friday 15 September 2017

How to customize a standard form in D365


Hello readers !!!!

Today i want to explain how to customize standard form in dynamics 365.

Task

To filter purchase order form with default open order status.

  1.       Create a form extension


                PurchTable
    


 2     Go to –>> Purchtable Datasource >> Events >> Copy Event handler method



3.       Create a new menu item with the form Purchtable
4.     Create a new class  and paste the event handler and write your own logic


class DIPL_PurchTableOpenOrder
{
   
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::Initialized)]
    public static void PurchTable_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun     fromRun;
        DataSourceName  ds;
        Query           q ;    
       
        fromRun = sender.formRun();

        if(fromRun.args().menuItemName() == menuItemDisplayStr(DIPL_OpenPurchTable))
        {
            q = sender.query();
            q.dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable, PurchStatus)).value(queryValue(PurchStatus::Backorder));
        }
       
    }

}



5.  Check in the front end whether our customized form is added or not 


Output



Thursday 29 June 2017

Create New customer address and update customer address using x++ code

How to update customer address using Code
static void updateCustomerAddress(Args _args)
{
    LogisticsPostalAddress      address;
    CustTable                   custtable;
    DirPartyPostalAddressView   postaladdressView;
    DirParty                    dirparty;
    LogisticsLocation           location;
    DirPartyTable               dirPartyTable;
   
    while select custtable where custtable.AccountNum == "100"
                         join  dirPartyTable where custtable.Party ==   dirPartyTable.RecId
                         join  location where dirPartyTable.PrimaryAddressLocation == location.RecId
                         join  address  where address.Location == location.RecId
    {
        if(location.RecId)
        {
            ttsBegin;       
                location.Description = "Test";
                location.selectForUpdate(true);
                location.update();  
            ttsCommit;
        }
        if(address.RecId)
        {
            ttsBegin;       
       
            address.Street  =   "Test";
            //address.ZipCode =   //"555111";
            //address.City    = "hyderabad";
            //address.CountryRegionId = "Ind";
            address.Address = address.Street +" "+ address.ZipCode +" "+ address.City +" "+address.CountryRegionId;
            address.selectForUpdate(true);
            address.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            address.update();
            ttsCommit;
        }
        info(strFmt("Customer %1 Description %2 Address %3",custtable.AccountNum,location.Description,address.Address));
    }

}

How to create new customer address using x++ code
static void createCustomerAddress(Args _args)
{
    LogisticsPostalAddress address;  
    DirPartyPostalAddressView   addressView;
    DirParty dirParty;
    DirPartyTable   dirPartyTable;
    CustTable   custTable;
    container  roles;
   
    while select custTable
          join  dirPartyTable where custtable.Party ==   dirPartyTable.RecId
            && DirPartyTable.Name like "Test*"
    {  
        address.Street = custTable.name() +"\n"+ "Avenue";  
        address.ZipCode = "08837";  
        address.City = "Edison";  
        address.State = "NJ";
        address.CountryRegionId = "USA";
        addressView.IsPrimary = 1;
        addressView.LocationName = "USTC";
        addressView.Party = CustTable.Party;  
        addressview.initFromPostalAddress(address);  
        DirParty = DirParty::constructFromPartyRecId(CustTable.Party);  
        roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];  
        DirParty.createOrUpdatePostalAddress(addressView,roles);
        info(strFmt("Customer %1 Description %2 Address %3",custtable.AccountNum,addressView.LocationName,address.Street));
    }
         info("done");

 }

Wednesday 31 May 2017

Errors With solutions in Ax

#1387 > MSG_Presence















Solution

Reinstall the client


MR Permissions




Solution
System Administrator ------> Users
add a user to Ax 2012 and you give him the roles of Accounting Manager, synchronization is done automatically between Ax and Management Reporter 2012.
You start the MR then go the Security tab you will find the new user added.
You do not need to add a user on MR.



Error message: "For more information about this error navigate to the report server on the local server machine, or enable remote errors"

Solution : 
https://community.dynamics.com/ax/b/axtipsandtricks/archive/2015/03/30/what-to-do-error-to-navigate-to-the-report-server-enable-remote-errors


Error message: Cannot create a record in Tax Information of Vendor (TaxInformationVendTable_IN). The record already exists.

Solution : 

https://dynamicsuser.net/ax/f/developers/88688/cannot-create-a-record-in-tax-information-of-vendor-taxinformationvendtable_in-the-record-already-exists

Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record.

Solution :
If it is temp table, change property Savedatapercompany : NO

                                      ( or )
follow the link
http://microsoft-dynamics-ax-erp.blogspot.in/2015/03/changecompany-and-table-buffers.html


Sales Invoice Reports with different Report Design

You have to override the "outputReport" method in controller class.

public void outputReport()
{
   str reportDesign = 'SalesInvoice.Report1';
   this.parmReportName(reportDesign);
   this.parmReportContract().parmReportName(reportDesign);
   formLetterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
   super();
}


Report time out issue


DP extends SrsReportDataProviderPreProcessTempDB

https://www.tech.alirazazaidi.com/how-to-handle-long-running-reports-in-dynamics-ax-2012-r3/


Third party ISV's available Microsoft
https://appsource.microsoft.com/en-us/marketplace/apps?search=to-increase&page=1

Thursday 11 May 2017

How to get user based security roles using x++ code in Ax 2012 R3

Export user based roles in Ax 2012 R3

static void Export_Userbasedroles(Args _args)
{
    SysExcelApplication         xlsApplication;
    SysExcelWorkBooks           xlsWorkBookCollection;
    SysExcelWorkBook            xlsWorkBook;
    SysExcelWorkSheets          xlsWorkSheetCollection;
    SysExcelWorkSheet           xlsWorkSheet;
    SysExcelRange               xlsRange;
    CustTable                   custTable;
    int                         row = 1;
    str                         fileName;
    SecurityUserRole            _SecurityUserRole;
    SecurityRoleTaskGrant       _SecurityRoleTaskGrant;
    SecurityTask                _SecurityTask;
    SecurityRole                _SecurityRole;
    UserInfo                    _UserInfo;
    
    fileName = @"C:\Users\Rajendra\Desktop\Roles.xlsx";
    xlsApplication           = SysExcelApplication::construct();
    xlsWorkBookCollection    = xlsApplication.workbooks();
    xlsWorkBook              = xlsWorkBookCollection.add();
    xlsWorkSheetCollection   = xlsWorkBook.worksheets();
    xlsWorkSheet             = xlsWorkSheetCollection.itemFromNum(1);
    xlsWorkSheet.cells().item(row,1).value("User Role");
    xlsWorkSheet.cells().item(row,2).value("User Id");
    xlsWorkSheet.cells().item(row,3).value("Legal Entity");
    row++;

    while select _UserInfo
    {
        while select _SecurityUserRole where _SecurityUserRole.User==_UserInfo.id
        {
                while select _SecurityRole where _SecurityRole.RecId==_SecurityUserRole.SecurityRole
                {
                    xlsWorkSheet.cells().item(row,1).value(_SecurityRole.Name);
                    xlsWorkSheet.cells().item(row,2).value(_UserInfo.id);
                    xlsWorkSheet.cells().item(row,3).value(_UserInfo.company);
                    row++;
                }
        }
    }
   
    if(WinApi::fileExists(fileName))
        WinApi::deleteFile(fileName);
    xlsWorkbook.saveAs(fileName);
    xlsApplication.visible(true);

}

From reference 

Sunday 7 May 2017

How to update financial dimensions for master data using x++ code in Ax 2012

Customers

To update financial dimensions to all legal entities.

static void updateCustomerDimensions(Args _args)
{
    CustTable       custTable;
 
    Struct struct;// = new Struct();
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault;
    CompanyInfo         companyInfo;

    while select companyInfo where companyInfo.DataArea !="DAT"
    {
        struct = new struct();
        com = conNull();
        changeCompany(companyInfo.DataArea)
        {
            ledgerDimension =conNull();
            com = conIns(com,1,companyInfo.DataArea);
         
            struct.add('LegalEntity',companyInfo.DataArea);
            ledgerDimension += struct.fields();
            ledgerDimension += struct.fieldName(1);
            ledgerDimension += struct.valueIndex(1);


            DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
            //Customers
         
            while select forUpdate crossCompany:com * from custTable
            {
                if(custTable.RecId)
                {
                    ttsBegin;
                    custTable.DefaultDimension = DimensionDefault;
                    custTable.update();
                    info(strFmt("Customer %1 dimension updated -- %2",custTable.AccountNum,custTable.dataAreaId));
                    ttsCommit;
                }
            }
        }
    }


}

Fixed asset

static void updateAssetDimensions(Args _args)
{
    AssetTable      assetTable;
    AssetBook       assetBook;
    Struct struct;// = new Struct();
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault;
    CompanyInfo         companyInfo;

    while select companyInfo where companyInfo.DataArea !="DAT"
    {
        struct = new struct();
        com = conNull();
        changeCompany(companyInfo.DataArea)
        {
            ledgerDimension =conNull();
            com = conIns(com,1,companyInfo.DataArea);

            struct.add('LegalEntity',companyInfo.DataArea);
            ledgerDimension += struct.fields();
            ledgerDimension += struct.fieldName(1);
            ledgerDimension += struct.valueIndex(1);


            DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
            //Vendors

            while select forUpdate crossCompany:com * from assetBook
            {
                if(assetBook.RecId)
                {
                    ttsBegin;
                    assetBook.DefaultDimension = DimensionDefault;
                    assetBook.update();
                    info(strFmt("Asset %1 dimension updated -- %2",assetBook.assetid,assetBook.dataAreaId));
                    ttsCommit;
                }
            }
        }
    }


}

Update financial dimensions for master data

static void testUpdateCustomerDimensions(Args _args)
{
    CustTable           custTable;
    Struct              struct;
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault,custDimensionDefault;
    CompanyInfo         companyInfo;

    DimensionAttributeValueSetStorage    dimStorage;
    Counter                              i;
    str                                  BusUnit,CCUnit,Dep,IG;
    ProjId                               projId;
    container                            conDefaultdim;

    struct = new struct();
    com = conNull();

    ledgerDimension =conNull();

    select forUpdate custTable where custTable.AccountNum =="US-011";

    custDimensionDefault = custTable.DefaultDimension;

    dimStorage = DimensionAttributeValueSetStorage::find(custDimensionDefault); //default dimension value

    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnit")
        {
            BusUnit = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "CostCenter")
        {
            CCUnit = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Department")
        {
            Dep = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "ItemGroup")
        {
            IG = dimStorage.getDisplayValueByIndex(i);
        }


        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Project")
        {
            projId = "000003";//dimStorage.getDisplayValueByIndex(i);
        }

    }
    //projId = "000002";

    conDefaultdim = [5,'BusinessUnit',BusUnit,'CostCenter',CCUnit,'Department',Dep,'ItemGroup',IG,'Project',projId];

    DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(conDefaultdim);

    if(custTable.RecId)
    {
        ttsBegin;
        custTable.DefaultDimension = DimensionDefault;
        custTable.update();
        info(strFmt("Customer %1 dimension updated -- %2",custTable.AccountNum,custTable.dataAreaId));
        ttsCommit;
    }


}