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


}