Wednesday, 20 June 2018

job to Update Internal Customers - custTable - AX2012 in all companies (crosscompany)

UpdateInternalCustomers

using cross Company in AX2012 we can update the custTable Table in all the companies in AX

    static void KTI_UpdateInternalCustomers(Args _args)
    {
        CustTable   custTable;
        DataArea    dataArea;
   
        ttsBegin;
        while select forupdate crossCompany * from custTable
            where custTable.AccountNum LIKE "I*"  &&
                  custTable.CustGroup  == "INT"
        {
            changeCompany(custTable.dataAreaId)
            {
               custTable.PriceGroup        = "INT";
                custTable.SuppItemGroupId   = "INT";
                custTable.doUpdate();
            }
        }
        ttsCommit;
    }

Friday, 2 February 2018

To put an item on-hold in AX2012

static void onhold(Args _args)
{
    InventItemInventSetup inventItemInventSetup;

    while select forupdate inventItemInventSetup where inventItemInventSetup.ItemId=="1111111111"
    {
     if (inventItemInventSetup.InventDimId == "TH02-000001")
      {
        ttsBegin;
        inventItemInventSetup.Stopped = NoYes::No;
        inventItemInventSetup.update();
        ttsCommit;
        info("success");
      }
    }
}

CrossCompany insert Code in AX2012

CrossCompany insert Code


The following code are my Test.i cant assure that this code will work as you expect.



static void crosscompantinsert(Args _args)
{

    TMSSalesTable tableFrom,tableTo;

    str destinationCompany="USRT";

    str curCompany;

    #avifiles
    SysOperationProgress  oProgress;
    int                   nTotal;

    #define.TITLE("Copying data...");

        curCompany=curext();
    if(curCompany=="USMF")
    {

    select count(RecId) from tableFrom;

   // nTotal=tableFrom.RecId;

    oProgress=SysOperationProgress::newGeneral(#aviUpdate,#TITLE,nTotal);

    tableFrom.clear();

    while select tableFrom
    {
        changeCompany(destinationCompany)
        {
            tableTo=null;

            ttsBegin;

            buf2Buf(tableFrom,tableTo);
            tableTo.insert();

            ttsCommit;
        }

        oProgress.incCount();

    }

    oProgress.hide();
    }

    else
    {
        info("Cannot be processed");

}
}

Journal mismatch in ax2012 Sample code X++ in AX2012

static void journalMismatch(Args _args)
{
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    COMVariantType          type;
    System.DateTime         ShlefDate;
    FilenameOpen            filename;
    dialogField             dialogFilename;
    Dialog                  dialog;
    SysLabelEdit            SysLabelEdit;
    LabelId                 varLabelId;
    LabelType               labelType;
    LabelDescription        labelDescription;
    ItemIdInventoried       itemid;
    InventJournalTrans      inventJourTrans;
    DimensionAttributeValueCombination  dimAttr;
    GeneralJournalAccountEntry  generalJour;
    int                     asp;
    boolean                 changeStatus;
    real                    mainAccount,movementJour;

    //Table Declarations Start
    int row = 1;


    // convert into str from excel cell value
    str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
    {
    switch (_cv.variantType())
    {
    case (COMVariantType::VT_BSTR):
    return _cv.bStr();
    case (COMVariantType::VT_R4):
    return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
    case (COMVariantType::VT_R8):
    return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
    case (COMVariantType::VT_DECIMAL):
    return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
    case (COMVariantType::VT_DATE):
    return date2str(_cv.date(),123,2,1,2,1,4);
    case (COMVariantType::VT_EMPTY):
    return "";
    default:
    throw error(strfmt("@SYS26908", _cv.variantType()));
    }
    return "";
    }
    ;

    SysLabelEdit = new SysLabelEdit();
    dialog = new Dialog("Excel Upoad");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);
    dialog.filenameLookupTitle("Upload from Excel");
    dialog.caption("Excel Upload");
    dialogFilename.value(filename);
    if(!dialog.run())
    return;
    filename = dialogFilename.value();
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    try
    {
    workbooks.open(filename);
    }
    catch (Exception::Error)
    {
    throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
    {
        ttsBegin;
        row++;
        asp++;
        itemid          = COMVariant2Str(cells.item(row,2).value());

        select inventJourTrans
            where inventJourTrans.ItemId == itemid;
        if(inventJourTrans) //if the inventjourTrans is present
        {
            mainAccount = inventJourTrans.CostAmount;
            select dimAttr
            where dimAttr.RecId == inventJourTrans.LedgerDimension;
            if(dimAttr)      //for the above if dimAttr is present
            {
                select generalJour
                where generalJour.LedgerDimension == dimAttr.RecId;
                if(generalJour)
                {
                    movementJour = generalJour.AccountingCurrencyAmount;
                    if(mainAccount != movementJour)
                    {
                        info(strFmt("%1 %2 %3",inventJourTrans.RecId,mainAccount,movementJour));
                    }
                }
            }
        }
        ttsCommit;
    }
    while (type != COMVariantType::VT_EMPTY);
    info(strFmt("%1",asp));
 
    info(strFmt("labels updated"));
    application.quit();


}

Tuesday, 12 December 2017

Debugging-an-RDP-class-based-ssrs-report-in-ax-2012


 Debugging-an-RDP-class-based-ssrs-report-in-ax-2012


Follow the Given Steps:

 1.   In classDeclaration extend SrsReportDataProviderPreProcess instead of SrsReportDataProviderBase 
 2.  Temp table properties should be
     (a) Table type : Regular instead of tempDB 
     (b)  Created by : Yes
     (c) Created Transaction Id : Yes
 3. In process report of the class add this line   Temporarytablename.setConnection(this.parmUserConnection());

 Now you Start debugging. 




Common Error that occur in ssrs report :


Cannot edit a record in General journal entries that have not been posted (LedgerOpenTransactionsTmp).
The SQL database has issued an error.
SQL error description: [Microsoft][SQL Server Native Client 11.0][SQL Server]String or binary data would be truncated.
SQL statement: UPDATE T1 SET OFFSETACCOUNTNAME=T4.NAME,OFFSETLEDGERACCOUNT=T2.DISPLAYVALUE,RECVERSION=? FROM ...


Solution: 


This Error Generally occurs when there is a mismatch in the EDT of the Fields in "LedgerOpenTransactionsTmp" Table.

Example:

Changing the field AccountName's EDT AccountName to DirPartyName will resolve this problem .
or in some cases
 Changing the field OffsetAccountName's EDT AccountName to DirPartyName will resolve this problem .

Wednesday, 29 November 2017

How to reduce/flush the TempDB size in AX2012

How to reduce/flush the TempDB size in AX2012

 

 

In AX 2012 all the temp data is stored in TempDB database, which normally occupies alot of space after certain days. Below is the path for TempDB:

<YourDrive>:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\TempDB






You might see on the above path that there is a a database which is of a big size in GB's. You simply need to restart SQL Server service or restart the machine. This will flush all the temp memory from this database.

Hope this helps!

Tuesday, 28 November 2017

Multiselect in Grid (AX2012)

Multiselect in Grid (AX2012)


Multiselect in a grid is set to "No" By default.

you can Enable it by clicking on the Grid ->properties.

   Multiselct -Yes

Now you can multiselect on the Grid




For Further info:

Overriding Clicked method to get the selected Records in Grid

on the button field -> Method > overideMethod > Clicked

and paste the Following Code



void clicked()
{
    Table ta;   //Here Table name  is "Table"
 
     ta=Table_ds.getFirst(true);

        while(ta.RecId)
    {

        info(strFmt("you have Selected %1",ta.Name));
      
      //ta.delete();  //enable it to delete the selected items
   
        ta=Table_ds.getNext();


    }

}
 

job to Update Internal Customers - custTable - AX2012 in all companies (crosscompany)

UpdateInternalCustomers using cross Company in AX2012 we can update the custTable Table in all the companies in AX     static void KTI_...