Dynamics AX

Welcome to my Dynamics AX playground!

Home     Articles     Dynamics AX - Trivia     Dynamics AX Search     Mohammed Rasheed     Contact Me     My Dynamics Ax Blog      
Guide to Setup SSRS with
Add Fields to a Table Using Code
Code to view Ledger Transaction Details
AX Mobile - Installation and Configuration
Forecasting in Dynamics AX 2009
Multi Threaded Programming in DAX
OLAP - Installation and Configuration
Send Text Messages (SMS) from DAX
Sending Emails from DAX without Outlook.
Using Data Definition Groups
A View Thing..
All About Maps..
COM Class Wrapper
Create a Role Centre
Create and Post Counting
Outlook 07 Integration
Alerts to Multiple Users
Counting Lines of Code
 
 

Quick and Dirty Code to Create and Post Counting Journals in Dynamics AX

 

A couple of guys asked me for code to import inventory in to ax using Counting journals... so here goes..

 

I basically created a table, called StockLevelImport and added basic fields to it such as itemid, location, warehouse, size,colour and quantity..

Notice: other dimensions such as config, batch were not added..however you can easily do so if you like.

 

The following bit of code was use to import the stock file in to ax (basically import a csv file)

 

static int importFromFile()

{

    CommaIo                 fileIn;

    StockLevelImport   stockLevelImport;

    container               fileInCon;

    FileIOPermission        perm;

    int                     recordsInserted;

 

    ;

    #stockLevelImport

// the macro holds the full file name

    recordsInserted = 0;

 

    perm = new FileIOPermission(#stockLevelImportFile,'r');

    if (perm == null)

    {

        error("FileIoPermission error");

        return 0;

    }

    // Grants permission to execute the CommaIo.new method.

    // CommaIo.new runs under code access security.

    perm.assert();

 

    fileIn = new CommaIo(#stockLevelImportFile,'r');

 

    delete_from stockLevelImport; // clear table before import

 

    fileIn.inFieldDelimiter(',');

 

    startLengthyOperation();

 

    ttsbegin;

 

    while(fileIn.status() == IO_Status::Ok)

        {

            fileInCon = connull();

 

            fileInCon = fileIn.read();

 

            stockLevelImport.ItemId                 = conpeek(fileInCon,1);

            stockLevelImport.InventLocationId       = conpeek(fileInCon,2);

            stockLevelImport.WMSLocationId          = conpeek(fileInCon,3);

            stockLevelImport.InventQty              = conpeek(fileInCon,4);

            stockLevelImport.InventColorId          = conpeek(fileInCon,6);

            stockLevelImport.InventSizeId           = conpeek(fileInCon,5);

 

            if(fileIn.status() == IO_Status::Ok) // to prevent the last insert

                  stockLevelImport.insert();

 

            recordsInserted++;

        }

    ttscommit;

 

    endLengthyOperation();

 

    CodeAccessPermission::revertAssert();

 

    return recordsInserted;

 

}