Sunday, 7 June 2015

Currency Conversion in Ax through X++ Code

static void CurrencyConversion(Args _args)
{
   CurrencyExchHelper currencyExchangeHelper;
   AmountMst amountMST;
   CurrencyCode transCurrency;
   AmountCur amountCur;
   ;
   amountCur = 5000.00;
   currencyExchangeHelper = CurrencyExchHelper::newExchDate(“KSI”,”USD”,systemDateGet());
   amountMST = currencyExchangeHelper.calculateAmountCurToMst(amountCur ,true);
   info(strFmt(“%1″,amountMST));
}
In Ms Dynamics Ax 2012
static void SR_CEHConversion(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = ‘EUR’;
AmountCur amountCur = 500.00;
AmountMst amountMST;

currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt(‘%1′,amountMST));
}

Sunday, 31 May 2015

Creation of Default Dimension

static void CreateDefaultDimension(Args _args)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully
    container               conAttr = ["Department", "ExpensePurpose", "Item"];
    container               conValue = ["00000028", "Training", "1000"];
    str                     dimValue;

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();
    info(strFmt("%1",result));
}

Sunday, 17 May 2015

Custom Lookup in Ax

public void lookup(FormControl _formControl, str _filterStr)
{
sysTableLookup sysTableLookup;
Query query = New Query();
QueryBuildDataSource qbdsJour, qbdsTrans,qdbsVend;
QueryBuildRange qbr;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(VendPackingSlipJour), _formControl);
qbdsJour = query.addDataSource(tableNum(VendPackingSlipJour));
qbdsTrans = qbdsJour.addDataSource(tableNum(VendPackingSlipTrans));

qbdsJour.relations(true);
qbr = qbdsTrans.addRange(fieldNum(VendPackingSlipTrans, ItemId));
qbr.value(<ItemId>);
qbdsTrans.relations(true);
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, GRNNumber_IN));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, PurchId));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, OrderAccount));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

}

Sunday, 26 April 2015

Importing Fixed Asset Opening Balance through CSV File

class CustFinancialDimension
{
}

static RecId createDimension(str custaccount)
{
    dimensionAttribute                  dimensionAttribute;
    dimensionAttributevalue             dimensionAttributevalue;
    DimensionAttributeValueSetStorage   dimstorage;
    RecId ret;
;


    dimStorage = new DimensionAttributeValueSetStorage();
    dimensionAttribute = AxdDimensionUtil::validateFinancialDimension("SystemGeneratedAttributeFixedAsset");
    dimensionAttributeValue = AxdDimensionUtil::validateFinancialDimensionValue(dimensionAttribute, custAccount);

    dimStorage.addItem(dimensionAttributeValue);

    ret = dimStorage.save();

    return Ret;

}
//------------------------------------------------------

public class FixedAssestsOpeningBalanceUpload extends RunBaseBatch
{
    LedgerJournalId         journalNum;
    DialogField                 dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
    Filename                    filename;
    TransDate                   TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
    NoYesID                     NoYes;
    Ledgerjournalnameid         Ledgerjournalnameid1,LedgerJournalNameId;
    CommaIo                     csvFile;
    currencycode                currencycode;
    args                        args;


    container                   readCon;
    container                   ledgerDimensions, offsetDimensions;
    counter                     icount,inserted;

    LedgerJournalTable      ledgerJournalTable;
    Map                     voucherMap;

    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro

    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro

    #File
}

public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));

    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    dialogFromDate      = dialog.addFieldValue(extendedtypestr(TransDate), TransactionDate,"TransactionDate");
    dialogledger        = dialog.addFieldvalue(extendedtypestr(LedgerJournalNameid),"JournalName","JournalName");
    //dialogcheckbox      = dialog.addFieldValue(enumstr(NoYes),"","Reversing","");

    return dialog;
}


public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    FromDate    = dialogFromDate.value();
    //NoYes      = dialogcheckbox.value();
    Ledgerjournalnameid1 = dialogledger.Value();

    return true;
}

public LedgerDimensionAccount getLedgerDimension(AccountNum _accountNum)
{
    MainAccount                 mainAccount;

    RefRecId                    accountStructureId;
    List                        dimensionList = new List(Types::Class);
    DimensionDefaultingEngine   dimensionDefaultingEngine;
    ;

    mainAccount = MainAccount::findByMainAccountId(_accountNum);

    accountStructureId = DimensionHierarchy::getAccountStructure(mainAccount.RecId);

    if(mainAccount)
    {
        dimensionDefaultingEngine = DimensionDefaultingEngine::constructForMainAccountId(mainAccount.RecId, accountStructureId);
        dimensionDefaultingEngine.applyDimensionSources(dimensionList);

    return dimensionDefaultingEngine.getLedgerDimension();
    }
    else
    return 0;
}

public LedgerJournalId parmJournalNum(LedgerJournalId _journalNum = journalNum)
{
    journalNum = _journalNum;
    return journalNum;
}

static void main(Args  args)
        {
            FixedAssestsOpeningBalanceUpload        FixedAssestsOpeningBalanceUpload;
            ledgerJournalTrans              ledgerJournalTrans;

            ;

            FixedAssestsOpeningBalanceUpload =  new FixedAssestsOpeningBalanceUpload();

            if(FixedAssestsOpeningBalanceUpload.prompt())
            {
                FixedAssestsOpeningBalanceUpload.run();
            }


}

void run()
{


    boolean                             first = true;
    MainAccount                         mainAccount;
    DimensionAttributeValueCombination  dimensionAttributeValueCombination;
    MainAccountNum                      mainAccountNum;
    NumberSequenceTable                 numberSequenceTable;
    LedgerJournalEngine_Daily           ledgerJournalEngine_Daily;
    Voucher                             voucher;
    DimensionLedgerAccountType          ledgerAccountType;
    str                                 accountType;
    Amount                              amountCurDebit,amountCurCredit,amtcrdt,amtdebt;
    container                           conSplitValue,dimm,offdim;
    projTable                           projTable;
    DimensionAttributeValueCombination  ledgerDimension,dimensionAttributeValueCombinationrecid;
    ProjId                              projid;
    JournalTableData                    JournalTableData;
    AxLedgerJournalTrans                trans  = new AxLedgerJournalTrans();
    AxLedgerJournalTable                header = new AxLedgerJournalTable();
    str                                 dimensn,offdimensn;
    str 64                              custAccount,ledgerAccount;
    CustTable                           custtable;
    dimensionAttribute                  dimensionAttribute;
    dimensionAttributevalue             dimensionAttributevalue;
    DimensionAttributeValueSetStorage   dimstorage;
    int64                              reccid;
    Struct struct = new Struct();
    container conledgerDimension;
    DimensionDefault DimensionDefault;
    str                                 costcenter,department,revenueDimension,description;
    //CISBillingInterfaceTable           cisBillingInterfaceTable;
    LedgerJournalACTypE                 acctype,offacctype;
    DimensionStorage                    DimensionStorage;

    LedgerJournalTrans ledgerJournalTrans;
    LedgerJournalTrans_Asset   ledgerJournalTransAssets;
    AssetTable                 assetTable ;
    LedgerDimensionDefaultAccount defaultAccount;
    LedgerJournalEngine           ledgerJournalEngine;
    AssetBook                  assetBook;
    str  64                       assetid;
    AssetTransTypeJournal       transtype;
    LedgerJournalName           ledgerJournalName;



    ;

    LedgerJournalNameId = Ledgerjournalnameid1;
    TransDate= Fromdate;

    csvFile = new CommaIO(filename, 'r');
    try
    {
        if (csvFile)
        {
            ttsbegin;
            if(first) //Create Journal Header
            {


                Select ledgerjournalname where ledgerjournalname.JournalName == LedgerJournalNameId;
                if(!ledgerJournalName.RecId)
                {
                    throw error ("ledgerJournalName doesn't exgist");
                }

                ledgerJournalTable.clear();
                ledgerJournalTable.initValue();
                ledgerJournalTable.JournalNum    = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
                ledgerJournalTable.journalType   = LedgerJournalType::Daily;
                ledgerJournalTable.JournalName   = ledgerJournalName.JournalName;
                ledgerJournalTable.Name          = ledgerJournalName.Name;

                ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
                ledgerJournalTable.insert();

                first = false;
            }

            numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(LedgerJournalNameId).NumberSequenceTable);

            voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();

            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();

                icount++;

                amountCurDebit = 0;
                amountCurCredit = 0;

                if (readCon && icount )//dont insert first record of file : header
                {


                    description = conPeek(readcon,1);
                    currencycode = conPeek(readCon,2);
                    acctype = conPeek(readCon,4);
                    amountCurDebit = conPeek(readCon,5);
                    amountCurCredit = conPeek(readCon,6);
                    ledgerAccount = conPeek(readCon,7);
                    assetid = conPeek(readCon,8);
                    transtype = conPeek(readCon,9);

                    ledgerJournalTrans.JournalNum           = ledgerJournalTable.JournalNum;




                    assetTable=assetTable::find(assetid);
                    select assetBook where assetBook.AssetId == assetid;

                    ledgerJournalTrans.CurrencyCode         =   currencyCode;
                    ledgerJournalTrans.initValue();

                    ledgerJournalTrans.LedgerDimension          = DimensionStorage::getDynamicAccount(assetid,acctype);
                    ledgerJournalTrans.parmAccount(AssetId, LedgerJournalACType::FixedAssets);
                    ledgerJournalTrans.TransDate            = transDate;

                    ledgerJournalTrans.Txt                  = description;
                    ledgerJournalTrans.AccountType          = acctype;
                    ledgerJournalTrans.Voucher              = voucher;
                    ledgerJournalTrans.PostingProfile           =AssetParameters::find().PostingProfile;
                    ledgerJournalTrans.Company              = curext();
                    ledgerJournalTrans.OffsetCompany        = curext();
                    ledgerJournalTrans.OffsetDefaultDimension = 0;
                    dimm = [ledgeraccount,ledgeraccount,"",""];
                    ledgerJournalTrans.OffsetAccountType    = LedgerJournalACType::Ledger;
                    ledgerJournalTrans.AmountCurCredit      =   amountCurCredit;
                    ledgerJournalTrans.AmountCurDebit       =   amountCurDebit;
                    ledgerJournalTrans.DefaultDimension     = CustFinancialDimension::CreateDimension(AssetId);
                    ledgerJournalTrans.OffsetAccountType    = ledgerJournalTable.OffsetAccountType;
                    ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(ledgerJournalTable.OffsetLedgerDimension, ledgerJournalTrans.DefaultDimension);


                    defaultAccount = AssetTable::find(assetTable.AssetId).assetOffsetLedgerDimension(ledgerJournalTrans.PostingProfile,
                                                                                                    AssetPost::assetTransTypeJournal2AssetTransType(AssetTransTypeJournal::Acquisition),
                                                                                                AssetBook.BookId);


                    ledgerJournalTrans.OffsetLedgerDimension = this.getLedgerDimension(ledgerAccount);

                    ledgerJournalTrans.calcAmountMST();

                    ledgerJournalTrans.insert();
                    ledgerJournalTransAssets.BookId         = assetBook.BookId;
                    ledgerJournalTransAssets.TransType      = AssetTransTypeJournal::Depreciation;
                    ledgerJournalTransAssets.AssetId        = ledgerJournalTrans.parmAccount();
                    ledgerJournalTransAssets.Company        = ledgerJournalTrans.Company;

                    ledgerJournalEngine = new LedgerJournalEngine();
                    ledgerJournalEngine.initDefaultDimension(ledgerJournalTrans, ledgerJournalTransAssets);


                    ledgerJournalTransAssets.RefRecId       = ledgerJournalTrans.RecId;
                    ledgerJournalTransAssets.insert();

                    inserted++;



                } // if ends

            } // while ends
            ttsCommit;
        }            // if ends
        icount--;

    } // try ends

    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

    args = new Args();
    args.record(LedgerJournalTable::find(ledgerjournaltable.JournalNum ));

    new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);

}

Sunday, 12 April 2015

Financial Dimensiont from Ledgerdimension

public static void FinancialDimensionfromLedgerDimension(Args _args)
{
    DimensionAttributeValueGroupCombination dimAttrValueGroupCombo;
    DimensionAttributeLevelValue    dimAttrLevelValue;
    DimensionAttributevalue              dimAttrValue;
    DimensionAttribute                  dimAttr;

    select RecId from dimAttrValueGroupCombo
        where dimAttrValueGroupCombo.DimensionAttributeValueCombination == 568939223
            join displayValue from dimAttrLevelValue
        where dimAttrLevelValue.DimensionAttributeValueGroup == dimAttrValueGroupCombo.DimensionAttributeValueGroup
            join RecId from dimAttrValue
        where dimAttrValue.RecId == dimAttrLevelValue.DimensionAttributeValue
            join Name from dimAttr
        where dimAttrValue.DimensionAttribute == dimAttr.RecId && dimAttr.Name == "MainAccount";
                Info(strfmt("Value of Dimension %1 is %2", dimAttr.Name,  dimAttrLevelValue.displayValue));
 

//costcenter

select RecId from dimAttrValueGroupCombo
        where dimAttrValueGroupCombo.DimensionAttributeValueCombination == 568939223
            join displayValue from dimAttrLevelValue
        where dimAttrLevelValue.DimensionAttributeValueGroup == dimAttrValueGroupCombo.DimensionAttributeValueGroup
            join RecId from dimAttrValue
        where dimAttrValue.RecId == dimAttrLevelValue.DimensionAttributeValue
            join Name from dimAttr
        where dimAttrValue.DimensionAttribute == dimAttr.RecId && dimAttr.Name == "Cost Center";
                Info(strfmt("Value of Dimension %1 is %2", dimAttr.Name,  dimAttrLevelValue.displayValue));


//Department
    select RecId from dimAttrValueGroupCombo
        where dimAttrValueGroupCombo.DimensionAttributeValueCombination == 568939223
            join displayValue from dimAttrLevelValue
        where dimAttrLevelValue.DimensionAttributeValueGroup == dimAttrValueGroupCombo.DimensionAttributeValueGroup
            join RecId from dimAttrValue
        where dimAttrValue.RecId == dimAttrLevelValue.DimensionAttributeValue
            join Name from dimAttr
        where dimAttrValue.DimensionAttribute == dimAttr.RecId && dimAttr.Name == "Department";
                Info(strfmt("Value of Dimension %1 is %2", dimAttr.Name,  dimAttrLevelValue.displayValue));

 
 


}

Sunday, 5 April 2015

Vendor Master import through csv file

ublic class VendorMasterImport extends RunBase
{
    CommaIo                     csvFile;
    Filename                    filename;
    DialogField                 dialogFilename;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro
    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro
    #File
}
public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    return dialog;
}

public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    return true;
}
void run()
{
    //CommaTextIO                             csvFile;
    container                               readCon;
    counter                                 icount,inserted;
    Dialog                                  dialog;
    DialogField                             dfFileName;
    DirPartyRecId                           partyRecId,contactPartyRecid;
    Name                                    name,contactName;
    VendTable                               vendtable;
    str                                     contactperson;
    DirPartyPostalAddressView               addressView;
    DirPartyContactInfoView                 contactView;
    ContactPerson                           contactpersonTable;
    LogisticsElectronicAddressMethodType    enumType;
    DirContactPersonsService                dirContactPersonsService;
    DirContactPersons                       dirContactPersons;
    DirContactPersons_ContactPerson         dirContactPersons_ContactPerson;
    DirContactPersons_Person                dirContactPersons_Person;
    DirContactPersons_PersonName            dirContactPersons_PersonName;
    AifEntityKeyList                        aifEntityKeyList, aifEntityKeyList_DirContactPerson;
    str                                     fName, mName, lName;
    VendAccount                             vendorAccount;
    DirParty                                dirParty;
    LogisticsPostalAddress                  address;
    LogisticsElectronicAddress              logisticsElectronicAddress;
    BinData                                 binData;
    str                                     stringImage;
    LogisticsAddressStateID                 stateId;
    str                                     accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;

    ;

    csvFile = new CommaIO(filename, 'r');
    try
    {
        if (csvFile)
        {
            ttsbegin;
            readCon = csvFile.read();
            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();
                if(readCon)
                {
                icount++;
                accountnum = conPeek(readCon,1);
                accountName = conPeek(readCon,2);
                phone = conPeek(readCon,3);
                fax = conPeek(readCon,4);
                vendgroup = conPeek(readCon,5);
                currency = conPeek(readCon,6);
                dlvmode = conPeek(readCon,7);
                paymtermid = conPeek(readCon,8);
                email = conPeek(readCon,9);
                mobile = conPeek(readCon,10);
                contactperson = conPeek(readCon,11);
                pobox = conPeek(readCon,12);
                countryid = conPeek(readCon,13);
                zipcode = conPeek(readCon,14);
                stateId = conPeek(readCon,15);
                city = conPeek(readCon,16);
                street = conPeek(readCon,17);


                ttsBegin;
                name = conPeek(readCon,2);
                if(!name)
                break;
                partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;

                vendtable.clear();
                vendtable.initValue();
                vendtable.Party = partyRecId;
                vendtable.AccountNum = accountnum;
                vendtable.VendGroup  = vendgroup;
                vendtable.Currency   = currency;
                //vendtable.Blocked    =
                vendtable.DlvMode    = dlvmode;
                vendtable.PaymTermId   = paymtermid;
                if(contactperson != '')
                {
                    contactname = ContactPerson;
                    ContactPerson::findOrCreateNameParty(partyRecId,contactname);
                }
                vendtable.insert();
                ttsCommit;

                stateId = subStr(stateId,1,25);

                address.PostBox = strLRTrim(PoBox);
                address.CountryRegionId = strLRTrim(Countryid);
                address.State = stateId;
                address.ZipCode = strLRTrim(ZipCode);
                address.Street  = strLRTrim(Street);
                //address.county = strLRTrim(conPeek(readCon,17));
                address.City    = strLRTrim(City);
                addressView.LocationName = name;
                addressView.IsPrimary = NoYes::Yes;
                addressView.Party = partyRecId;
                addressview.initFromPostalAddress(address);

                DirParty = DirParty::constructFromPartyRecId(addressView.Party );
                DirParty.createOrUpdatePostalAddress(addressView);

                contactView.LocationName = "Email";
                contactView.Locator      = strLRTrim(email);
                contactView.Type         = LogisticsElectronicAddressMethodType::Email;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);

                contactView.LocationName = "Mobile";
                contactView.Locator      = strLRTrim(mobile);
                contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);

                contactView.LocationName = "Phone";
                contactView.Locator      = strLRTrim(Phone);
                contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);

                contactView.LocationName = "Fax";
                contactView.Locator      = strLRTrim(Fax);
                contactView.Type         = LogisticsElectronicAddressMethodType::Fax;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
                inserted++;
                }
            }
            ttsCommit;
        }
        icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
}

static void main(Args  args)
{
    VendorMasterImport        VendorMasterImport;
    ;
    VendorMasterImport =  new VendorMasterImport();
    if(VendorMasterImport.prompt())
    {
        VendorMasterImport.run();
    }
}

Thursday, 12 March 2015

Chart of Account Import using CSV file

public class ChartOfAccountsMasterImport extends RunBase
{
    CommaIo                     csvFile;
    Filename                    filename;
    DialogField                 dialogFilename,dialogChartOfAccountsName;
    str                         ChartOfAccountsName;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro
    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro
    #File
}

public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialogFilename.value(filename);
    dialogChartOfAccountsName = dialog.addField(extendedTypeStr("Name"), "Chart of account name");
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    return dialog;
}

public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    ChartOfAccountsName     = diALOGChartOfAccountsName.value();
    return true;
}
void run()
{
    ChartOfAccountsService                      chartOfAccountsService;
    MainAccountContract                         mainAccountContract;
    CommaTextIo                                 file;
    container                                   rec;
    Name                                        ledgerChartOfAccountsName;
    MainAccountNum                              mainAccountId;
    DimensionLedgerAccountType                  dimensionledgerAccountType;
    MainAccountCategory                         MainAccountCategory;
    MainAccount                                 MainAccount;
    DimensionAttribute                          mainAccountDimAttribute;
    DimensionAttributeValue                     dimensionAttributeValue;
    DimensionAttributeValueTotallingCriteria    totalCriteria;
    AccountCategory                             _accountCategory;
    str                                         strOfAccounts, fromA, toA,MainAccountName;
    int                                         sep;
    container                                   readCon;
    counter                                     icount,inserted;
    ;

    csvFile = new CommaIO(filename, 'r');
    try
    {
        if (csvFile)
        {
            ttsbegin;
            readCon = csvFile.read();
            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();
                if(readCon)
                {
                    mainAccountId = conPeek(readCon, 1);//strlrTrim(
                    mainAccountName = conPeek(readCon, 2);
                    dimensionledgerAccountType = conPeek(readCon, 3);
                    _accountCategory = conPeek(readCon,4);
                    if(!mainAccountId)
                    continue;
                    if (!mainAccount::findByMainAccountId( mainAccountId , false, LedgerChartOfAccounts::findByName(ledgerChartOfAccountsName).RecId))
                    {
                        mainAccountContract = new MainAccountContract();
                        mainAccountContract.parmMainAccountId( mainAccountId );
                        mainAccountContract.parmName(mainAccountName);
                        mainAccountContract.parmLedgerChartOfAccounts(ChartOfAccountsName);
                        mainAccountContract.parmType(enum2int(dimensionledgerAccountType::Expense));
                        select firstonly mainAccountCategory where mainAccountCategory.AccountCategory == _accountCategory;
                        MainAccountContract.parmAccountCategoryRef(mainAccountCategory.AccountCategoryRef);
                        chartOfAccountsService = new ChartOfAccountsService();
                        chartOfAccountsService.createMainAccount(mainAccountContract);
                    }
                }
            }
            ttsCommit;
        }
        icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
}

static void main(Args  args)
{
    ChartOfAccountsMasterImport        ChartOfAccountsMasterImport;
    ;
    ChartOfAccountsMasterImport =  new ChartOfAccountsMasterImport();
    if(ChartOfAccountsMasterImport.prompt())
    {
        ChartOfAccountsMasterImport.run();
    }
}