Showing posts with label AX2012. Show all posts
Showing posts with label AX2012. Show all posts

Friday, September 27, 2019

AX 2012 Steps to use Data Transfer Tool

The following steps are used to transfer data from one transaction db to other. Generally it would be used when we need Production data in our Dev/Test environment.

Note: Data Transfer Tool should be installed


Login to SQL server
Restore Transaction & Model databases backup [Source]
•      Open Command prompt as administrator and Navigate to C:\Program Files (x86)\Microsoft Dynamics AX 2012 Test Data Transfer Tool (Beta) folder [In the server DTT installed]
Run following command to export data
        DP.exe EXPORT C:\[FolderName] [RESTOREDDBNAME] [SQLSERVER]
        [Data will be extracted as files in the mentioned folder]
Stop AOS of the destination instance
DP.exe IMPORT C:\[FolderName] [DESTINATIONDBNAME] [SQLSERVER]
Start AOS


Note: You need to reset your SID after restored if two instances are running in different active domain directory.


Regards,
Arun S. Keerthi




AX 2012 Retrieve ledger dimension for Customer/Vendor

DimensionStorage::accountNum2LedgerDimension(accountNum, LedgerJournalACType::Cust) 

Friday, June 22, 2018

AX 2012 List page multi select datasource records AX2012

There may be situation to select multiple records in the list page and send it to other class to do some operation on the selected records. Below code will help you handle the same.

Step 1: Create new List page / Use the existing list page

Step 2 : Add menu item button in the list page  (For this example, you added an action menu item to call a class)

Step 3 : Choose the Multi select property to 'Yes'

Step 4 :  In the main method of the called class, Initialize the FormRun object.

 FormRun formRun;

 formRun = args.caller();


Step 5 : Initialize FormDatasource object to get the active records from the List page.

FormDatasource fds;

fds = formRun.pageInteraction().page().activeRecord('ListPageDataSourceName').dataSource();

Step 6 : Fetch the records that are marked in the list page

Common record;
CustTable custTable;

for (record = getFirstSelection(fds); record; record = fds.getNext())
{    
     custTable = record;
}


Best Regards,
Arun S Keerthi

AX 2012 Get Next Continuous Voucher number through X++ AX2012

Below job will help to get the next voucher number for continuous number sequence marked.


static void _updateVoucher(Args _args)
{
    NumberSeq numberSeq;
    NumberSequenceTable numSeqTable;
    Voucher voucher;

   
    numberSeq = NumberSeq::newGetVoucherFromId(LedgerJournalName::find('JournalName').NumberSequenceTable, true, false, UnknownNoYes::No);   
    info(numberSeq.voucher());
    numberSeq.used();
   
}

Wednesday, February 21, 2018

AX 2009 AX 2012 Find India GST posted sales tax value AX2009 AX2012

Below job will bring the posted/estimated invoice tax for the sales order.

We can change the module as per the requirement and find the tax value


//Refer GSTInvoiceReport_IN class
static void _122173_Tax(Args _args)
{
    CustInvoiceJour                     invoiceJournal;
    ITaxDocument                        taxDocument;
    ITaxDocumentLine                    taxDocumentLine;
    ITaxDocumentLineEnumerator          taxDocumentLineEnumerator;
    ITaxDocumentComponentLine           taxDocumentComponentLine;
    ITaxDocumentComponentLineEnumerator componentLines;
;
    invoiceJournal = CustInvoiceJour::find('vouchernumber');
    taxDocument = TaxBusinessService::getTaxDocumentBySource(invoiceJournal.TableId, invoiceJournal.RecId);
    taxDocumentLineEnumerator = taxDocument.lines();
    while (taxDocumentLineEnumerator.moveNext())
    {
        taxDocumentLine = taxDocumentLineEnumerator.current();
        componentLines = taxDocumentLine.componentLines('GST');
        while (componentLines.moveNext())
        {
            taxDocumentComponentLine = componentLines.current();
            info (strfmt('%1', TaxGSTInvoiceHelper_IN::getTaxPayableAmount(taxDocumentComponentLine)));
        }
    }
}

Regards,
Arun S Keerthi

Friday, October 27, 2017

AX 2012 - Timezone hotfix to handle the Timezone / DST change AX2012

Hi All,

I found this post that Microsoft has brought a feature in AX 2012 that you can handle the timezone modification if any new change brought by the government.

Check out this post for more details,

https://msdn.microsoft.com/en-us/library/cc622312.aspx


Regards,
Arun S.Keerthi

Friday, October 6, 2017

AX 2009 AX 2012 Print Barcode AX2009 AX2012

Below display method prints Barcode for the item.  I tried this AX 2009 morphX Report. Please change the logic accordingly to fit you. I used CODE39 in the else if any item doesn't have any specific setup.

//BP Deviation Documented
display BarCodeString packItemBarCode()
{
    BarcodeSetup    barCodeSetup;
    BarcodeSetupId  barcodeSetupId;
    str             barCodeContents = VendPackingSlipTrans.ItemId;
    ;
    barcodeSetupId = InventItemBarcode::findPurchBarcodeDimension(VendPackingSlipTrans.ItemId,InventDim::find(VendPackingSlipTrans.InventDimId)).barcodeSetupId;
    if (barcodeSetupId)
    {
        barCodeSetup = BarcodeSetup::find(barcodeSetupId);
        barCode = barCodeSetup.barcode();
    }
    if(!barcodeSetupId)
    {
        barcodeSetupId = InventItemBarcode::findPurchBarcode(VendPackingSlipTrans.ItemId).barcodeSetupId;
        if (barcodeSetupId)
        {
            barCodeSetup = BarcodeSetup::find(barcodeSetupId);
            barCode = barCodeSetup.barcode();
        }
        else
        {
            select firstonly barCodeSetup
                where barCodeSetup.barcodeType == BarCodeType::Code39;
            barCode = barCodeSetup.barcode();
        }
    }

    if (barCodeSetup.validateBarcode(strupr(barCodeContents)))
    {
        barCode.string(true,strupr(barCodeContents),BarCodeContentType::Item);
        barCode.encode();
    }
    else
    {
        throw(error(strfmt("@SYS41409", barCode.barcodeType(), strupr(barCodeContents))));
    }

    packItemBarCode.fontSize(barCodeSetup.fontSize);
    packItemBarCode.font(barCodeSetup.fontName);

    super();

    if (!barCode)
        return '';

    return barCode.barcodeStr();
}

Regards,
Arun S.Keerthi

Thursday, July 20, 2017

AX 2009 AX 2012 Read a CSV file AX2009 AX2012

Hi All,

This post will help the new AX developers who want to write the X++ code to read a *.CSV file. The below job reads files from a folder one by one.

static void importCSVFile(Args _args)
{
    ASCIIIO file;
    Container fileRead;
    str       line;
    System.Array            fileArray;
    container               fileCon;
    int i, j;
    FilenameOpen            fileName;
    ;
 
    fileArray = System.IO.Directory::GetFiles(invoiceFilePath,"*.csv");
    for( i=0; i < ClrInterop::getAnyTypeForObject(fileArray.get_Length()); i++ )
    {
       fileCon = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(fileList.GetValue(i)));
    }
    for(j=1 ; j<= conlen(fileCon) ; j++)
    {
        fileName = conPeek(fileCon, j);
        file = new ASCIIIO(fileName, "R");
        file.inRecordDelimiter('\n');
        file.inFieldDelimiter(",");

        fileRead = file.read();
        while (file.status() == IO_STATUS::Ok)
        {
            fileRead = file.read();
            line = conpeek(fileRead, 1);
            if (line != "0")
            {
                    info (conPeek(fileRead, 1));//Column 1
                    info (conPeek(fileRead, 2));//Column 2
                    info (conPeek(fileRead, 3));//Column 3                 
            }
        }
    }
}

Regards,
K. Arunsubramaniam

Friday, July 14, 2017

AX 2009 AX 2012 Find Item On-Hand using select statement AX2009 AX2012

This job helps to find the Item On-hand by using the Select statement. It loops through the Inventsum and groups by Inventory dimension. You can add/remove the dimension of the InventDim table.

void exportItemOnHand()
{
    InventTable invTable;
    InventSum   inventSum;
    InventDim   inventDim, inventDim1;

    InventDimParm   invDimParm;
    Qty             availPhysical;
    TextBuffer      tb;
    ;
    tb = new TextBuffer();
    tb.appendText("Company,Item number,Site,Warehouse,Location,Configuration,Size,On-hand\n");
    select invTable where invTable.ItemId == "011029";
   
        while select inventSum
        join inventDim
        group by InventSiteid, InventLocationId, WMSLocationId, ConfigId, InventSizeId
        where   inventSum.InventDimId   == inventDim.inventDimId
        &&      inventSum.Closed        == NoYes::No
        &&      invTable.ItemId         == inventSum.ItemId       
        {
            inventDim1.InventSiteId      = inventDim.InventSiteId;
            inventDim1.InventLocationId  = inventDim.InventLocationId;
            inventDim1.wMSLocationId     = inventDim.wMSLocationId;
            inventDim1.configId          = inventDim.configId;
            inventDim1.InventSizeId      = inventDim.InventSizeId;


            inventDim1  =   InventDim::findOrCreate(inventDim1);
            invDimParm.initFromInventDim(InventDim::find(inventDim1.inventDimId));
            availPhysical   = InventSum::findSum(invTable.ItemId, inventDim1, invDimParm).availPhysical();

            tb.appendText(strfmt("%1,%2,%3,%4,%5,%6,%7,%8\n", strupr(curext()), invTable.ItemId, inventDim1.InventSiteId, inventDim1.InventLocationId,
            inventDim1.wMSLocationId, inventDim1.configId, inventDim1.InventSizeId, availPhysical));
        }
   
    tb.toFile("D:\sample.txt");
}

Regards,
K. Arunsubrmaniam

Friday, June 16, 2017

AX 2009 AX 2012 FTP Delete a from FTP AX2009 AX2012



Below code uses System.Net.Ftpwebrequest package in AX to integrate with FTP. This job demonstrates how to delete a file from FTP folder. Refer WebRequestMethods.Ftp Class for different actions.

static void FTPUploadFile(Args _args)
{
    System.Object ftpo;
    System.Net.FtpWebRequest request;
    System.IO.StreamReader reader;
    System.IO.Stream stream;
    System.IO.Stream responseStream;
    System.Net.NetworkCredential credential;
    ;
 
    ftpo = System.Net.WebRequest::Create("ftp://ftp.url.com/foldername/filename.txt");
    request = ftpo;
    credential = new System.Net.NetworkCredential("username", "password");
    request.set_Credentials(credential);
    request.set_Method("DELE");
    request.set_UsePassive(true);
    request.set_UseBinary(true);
    request.set_KeepAlive(false);
 
    request.GetResponse();
}

Regards,
Arun

AX 2009 AX 2012 FTP Upload a into FTP AX2009 AX2012



Below code uses System.Net.Ftpwebrequest package in AX to integrate with FTP. This job demonstrates how to upload a file into FTP folder. Refer WebRequestMethods.Ftp Class for different actions.

static void FTPUploadFile(Args _args)
{
    System.Object ftpo;
    System.Net.FtpWebRequest request;
    System.IO.StreamReader reader;
    System.IO.Stream stream;
    System.IO.StreamWriter writer;
    System.Byte[] byteArray;
    System.Text.Encoding encodingUTF8;
    System.IO.Stream responseStream;
    System.Net.NetworkCredential credential;
    str fileContent = "File content";
    int arrayLength;
    ;
 
    ftpo = System.Net.WebRequest::Create("ftp://ftp.url.com/foldername/filename.txt");
    request = ftpo;
    credential = new System.Net.NetworkCredential("username", "password");
    request.set_Credentials(credential);
    request.set_Method("STOR");
    request.set_UsePassive(true);
    request.set_UseBinary(true);
    request.set_KeepAlive(false);
 
    encodingUTF8 = System.Text.Encoding::get_UTF8();
    byteArray    = encodingUTF8.GetBytes(fileContent);
    arrayLength  = byteArray.get_Length();
 
    stream = request.GetRequestStream();
    stream.Write(byteArray, 0, arrayLength);
    stream.Close();
}

Regards,
K. Arunsubramaniam