Showing posts with label IMPORT. Show all posts
Showing posts with label IMPORT. Show all posts

Thursday, December 22, 2016

EXPORT MODEL AND IMPORT MODEL FILES IN AX 2012 POWERSHELL AND CMD COMMAND PROMPT

EXPORT MODEL AND IMPORT MODEL FILES IN AX 2012 POWERSHELL AND CMD COMMAND PROMPT

Export an .axmodel file (Windows PowerShell)

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Export Command Syntax :
    Export-AXModel –Model <name> -File <Filename.axmodel>
    Example : 
    Export-AXModel –Model SecurityModel -File C:\SecurityModel.axmodel


Import an .axmodel file (Windows PowerShell)
    1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
    2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Import Command Syntax :
    Install-AXModel -File <Filename.axmodel> -Details
    Exmaple :
    Install-AXModel -File C:\SecurityModel.axmodel -Details

AX2012 AXUTIL commands to Import and Export Models

// Export
AxUtil export /model:"TestModel" /file:TestModel.axmodel

// Import
AxUtil import /file:TestModel.axmodel

C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>AxUtil 

Saturday, April 16, 2016

CREATE XML : EXPORT DATA INTO XML : MICROSOFT DYNAMICS AX 2012

CREATE XML : EXPORT DATA INTO XML : MICROSOFT DYNAMICS AX 2012

class CreateXmlFile
{
}
public static void main(Args _args)
{
XmlDocument doc;
XmlElement nodeXml;
XmlElement nodeTable; XmlElement nodeAccount; XmlElement nodeName; MainAccount mainAccount;
#define.filename(@'C:\accounts.xml')
doc         = XmlDocument::newBlank();
nodeXml = doc.createElement('xml');
doc.appendChild(nodeXml);
while select RecId, MainAccountId, Name from mainAccount
{
nodeTable = doc.createElement(tableStr(MainAccount));
nodeTable.setAttribute(fieldStr(MainAccount, RecId), int642str(mainAccount.RecId));
nodeXml.appendChild(nodeTable);
nodeAccount = doc.createElement( fieldStr(MainAccount, MainAccountId));
nodeAccount.appendChild( doc.createTextNode(mainAccount.MainAccountId));
nodeTable.appendChild(nodeAccount);
nodeName = doc.createElement( fieldStr(MainAccount, Name));
nodeName.appendChild( doc.createTextNode(mainAccount.Name));
nodeTable.appendChild(nodeName);
}
doc.save(#filename);
info(strFmt("File %1 created.", #filename));
}

Run the class.

The XML file accounts.xml will be created in the specified folder.

Friday, April 15, 2016

IMPORT JOURNALS FROM EXCEL USING X++ IN AX 2009 ledgerJournalTable VOUCHER SYSEXCEL

Importing Journals from Excel using X++ in AX 2009

class VIKAS_ImportVendInvoiceJournalLines
{
    Dialog                         dialog;
    DialogField                    dialogfield;
    Filename                       filename;

    #AviFiles
    SysExcelApplication            application;
    SysExcelWorkbooks              workbooks;
    SysExcelWorkbook               workbook;
    SysExcelWorksheets             worksheets;
    SysExcelWorksheet              worksheet;
    SysExcelCells                  cells;
    COMVariantType                 type;
    COMVariantType                 typeModule;
    NumberSeq                      numberSeq;
    NumberSequenceTable            numSeqTable;

    str                            Name, num,text, currency,businessunit,account,accountType, department,offsetaccount,OffsetAccounttype;
    int64                          costcenter;
    real                           debit, credit;
    container                      Account1, offsetaccount1;
    str                            acc;
    date                           transdate;

    LedgerJournalName              ledgerJournalName;
    LedgerJournalTable             ledgerJournalTable;
    LedgerJournalTrans             ledgerJournalTrans;



    container                      cont1,cont2,offSetAcctPattern;
    int                            cnt;

    LedgerJournalAC                AccountNumb, offsetAccountnum;

    container                      ledgerDimension;

    LedgerJournalACType            LedgerJournalACType;
    boolean                        ret;

}
--------------------------------------------------------------------------------------------------------------------------


public void DataImport()
{
    str         mSBU,mDepartment,mCostCenter,mPurpose;
    str         oSBU,oDepartment,oCostCenter,oPurpose;
    str         invoice;
    str         TDSgroup,salesTaxGroup,itemSalesTax;
    date        documentdate;
    Voucher     voucher;






    SysOperationProgress progress = new SysOperationProgress();
    int                 row = 0;
    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1);
    cells       = worksheet.cells();


    ledgerJournalName = ledgerjournalname::find(ledgerjournaltable.JournalName);
    row = 1;

    do
    {
        row++;
        transdate       = cells.item(row, 1).value().date();
        Currency        = cells.item(row, 2).value().bStr();
        accountType     = cells.item(row, 3).value().bStr();
        switch(cells.item(row, 4).value().variantType())
        {
            case COMVariantType::VT_BSTR:
                AccountNumb = strFmt("%1", cells.item(row, 4).value().bStr());
                break;
            case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
                AccountNumb = strFmt("%1", any2int(cells.item(row, 4).value().double()));
                break;
            case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
                AccountNumb = strFmt("%1", cells.item(row, 4).value().int());
                break;
            case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
                AccountNumb = strFmt("%1", cells.item(row, 4).value().uLong());
                break;
            case COMVariantType::VT_EMPTY:
                AccountNumb = '';
                break;
            default:
                throw error(strfmt('Unhandled variant type (%1).', cells.item(row+1, 1).value().variantType()));
        }
        mSBU            = cells.item(row, 5).value().bStr();
        mDepartment     = cells.item(row, 6).value().bStr();
        mCostCenter     = cells.item(row, 7).value().bStr();
        mPurpose        = cells.item(row, 8).value().bStr();
        invoice         = cells.item(row, 9).value().bStr();
        Text            = cells.item(row, 10).value().bStr();
        Debit           = any2real(cells.item(row, 11).value().double());
        Credit          = any2real(cells.item(row, 12).value().double());
        OffsetAccounttype = cells.item(row, 13).value().bStr();

        switch(cells.item(row, 14).value().variantType())
        {
            case COMVariantType::VT_BSTR:
                offsetAccountnum = strFmt("%1", cells.item(row, 14).value().bStr());
                break;
            case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
                offsetAccountnum = strFmt("%1", any2int(cells.item(row, 14).value().double()));
                break;
            case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
                offsetAccountnum = strFmt("%1", cells.item(row, 14).value().int());
                break;
            case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
                offsetAccountnum = strFmt("%1", cells.item(row, 14).value().uLong());
                break;
            case COMVariantType::VT_EMPTY:
                offsetAccountnum = '';
                break;
            default:
                throw error(strfmt('Unhandled variant type (%1).', cells.item(row, 1).value().variantType()));
        }
        oSBU            = cells.item(row, 15).value().bStr();
        oDepartment     = cells.item(row, 16).value().bStr();
        oCostCenter     = cells.item(row, 17).value().bStr();
        oPurpose        = cells.item(row, 18).value().bStr();
        TDSgroup        = cells.item(row, 19).value().bStr();
        salesTaxGroup   = cells.item(row, 20).value().bStr();
        itemSalesTax    = cells.item(row, 21).value().bStr();
        documentdate    = cells.item(row, 22).value().date();

        //In Excel cell should be in Text format
        try
        {
            ttsbegin;

            ledgerJournalTrans.clear();
            ledgerJournalTrans.initValue();
            ledgerJournalTrans.JournalNum   = ledgerJournalTable.JournalNum;
            ledgerJournalTrans.TransDate    = transdate;
            ledgerJournalTrans.Dimension[1] = mSBU;
            ledgerJournalTrans.Dimension[2] = mDepartment;
            ledgerJournalTrans.Dimension[3] = mCostCenter;
            ledgerJournalTrans.Dimension[4] = mPurpose;

            //select firstOnly numSeqTable
            //    where numSeqTable.RecId  == ledgerJournalName.NumberSequenceTable;
            if (!voucher)
            {
                numberseq = numberseq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
                voucher = numberseq.voucher();
            }
            ledgerJournalTrans.Voucher              = voucher;
            ledgerJournalTrans.AccountType          = str2enum(LedgerJournalACType, accountType);


            ledgerJournalTrans.AccountNum           = AccountNumb;
            ledgerJournalTrans.Txt                  = Text;
            ledgerJournalTrans.CurrencyCode         = Currency;
            ledgerJournalTrans.AmountCurDebit       = Debit;
            ledgerJournalTrans.AmountCurCredit      = Credit;
            ledgerJournalTrans.OffsetAccountType    = str2enum(LedgerJournalACType, offsetaccountType);
            ledgerJournalTrans.OffsetAccount        = offsetAccountnum;
            ledgerJournalTrans.Invoice              = invoice;
            ledgerJournalTrans.TaxGroup             = salesTaxGroup;
            ledgerJournalTrans.TaxItemGroup         = itemSalesTax;
            ledgerJournalTrans.DocumentDate         = documentdate;
            ledgerJournalTrans.TDSGroup_IN          = TDSgroup;


            if (ledgerJournalTrans.validateWrite())
            {
                ledgerJournalTrans.insert();

            }

            ttscommit;


            type = cells.item(row+1, 1).value().variantType();
        }
        catch(Exception::Error)
        {
            info(strFmt('Catched an error in row: %1',row));
        }


        info(strFmt('journal inserted %1',ledgerJournalTable.JournalNum));

    }

    while (type != COMVariantType::VT_EMPTY);
    application.quit();
}

-------------------------------------------------------------------------------------------------------------------------

public void run(Args _args)
{

    ;
    LedgerJournalTable = _args.record();
    dialog = new dialog('Excel Import');
    dialogfield = dialog.addField(TypeId(FilenameOpen), 'File Name');

    dialog.run();

    if(dialog.run())
    {
        filename =(dialogfield.value());
    }

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    if(filename)
    {
        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error('File cannot be opened.');
        }
        this.DataImport();



    }
}

-------------------------------------------------------------------------------------------------------------------------

public static void main(Args args)
{
    VIKAS_ImportVendInvoiceJournalLines import = new VIKAS_ImportVendInvoiceJournalLines();
    import.run(args);

}

--------------------------------------------------------------------------------------------------------------------------

void clicked()
{
    FormRun callerForm;
    Args args = new Args();

    VIKAS_ImportVendInvoiceJournalLines VIKAS_ImportVendInvoiceJournalLines = new         VIKAS_ImportVendInvoiceJournalLines();
    ;
    args.record(ledgerjournaltable);
    VIKAS_ImportVendInvoiceJournalLines.run(args);

    callerForm          = element.args().caller();
    callerForm.dataSource().refresh();
    callerForm.dataSource().reread();

}


Related Posts Plugin for WordPress, Blogger...