Tuesday, 13 November 2018

Get customized objects for different layer in Ax 2012

Get customized objects for different layer



Get customized objects for different layer


You might have the question that how to find the list of objects that are customized in user or cus layer in AX 2012 ? how to get list of customized objects in AX ? here are the steps to achieve that in AX 2009 and AX 2012.

Follow the steps to identify the all the customized objects by layer (USR, CUS, VAR, ISV)

Step 1: Create a new shared project.


You can rename your project as desired, we'll call it Customization_USR for now. Then open the newly created project.

Step 2: Choose Advanced Filter/Sort from the toolbar.


After opening the project click on Advance filter as shown in above image.

I want to group the objects same as in the AOT. So choose AOT for Groupings.

Step 3: Select the required objects.

Use the Select button on the dialog to select the objects you require for your project.
We want select all AOT objects from a specific layer, so we'll use the SysModelLayer / Layer field in the selection criteria for AX 2012.

For AX 2012 R2

Tuesday, 23 October 2018

Create Daily journal in Ax 2012

Daily Journal Create

//daily journal create and payment and settled
//Class Declaration .......................
public Class DailyJournalCreate
{
    ledgerJournalTableExt      ledgerJournalTableExt;
    LedgerJournalTransExt      ledgerJournalTransExt;
    ledgerJournalTable            ledgerJournalTableloc;
    ledgerJournalTrans            ledgerJournalTransloc;
}

//Importing  journals---------------------------------------------------------------(method)
Public void CImport(LedgerJournalTrans   _ledgerJournalTrans,int _row)
{

    int                                         WrkShtNum;
    COMVariantType                              type;
    Name                                        AccountTypeId,markedInvoice,dim3,dim4,dim5,AccountNum,LedgerAccountValue,
                                                LedgerOffsetAccountValue,OffsetAccount,dim6,dim7,offdim1,
                                                formatValue,offdim3,offdim4,offdim5,offdim6,offdim7;
    LedgerJournalTransTaxExtensionIN            LedgerJournalTransTaxExtensionIN;
    LedgerDimensionAccount                      LedgerDim,DefDimension;
    LedgerDimensionAccount                      OffsetledgerDim;
    LedgerJournalTrans                          ledgerJournalTrans;
    ledgerJournalTable                          ledgerJournalTable,ledgerJournalTab;
    LedgerJournalACType                         OffsetAccountType;
    TransDate                                   transDate;
    CurrencyCode                                currencyCode;
    NoYes                                       noYes;
    LedgerJournalNameId                         ledgerJournalNameId;
    numberSeq                                   numberSeq;
    AmountCur                                   AmountCurCredit,AmountCurDebit;
    boolean                                     value;
    SalesParameters                             salesParameters;
    LedgerJournalCheckPost                      _LedgerJournalCheckPost;
    CustTransOpen                               custTransOpen;
    DimensionAttributeValueCombination          dim;
    AccountNum                                  journal;
    int                                         i,j;
    int                                         row;
    str 250                                     error;
    Dimension                                   accountingRegion;
    recid                                       ledger;

    select salesParameters;
    if(_row==1)
    {
       ttsbegin;

        ledgerJournalTableloc.JournalName = salesParameters.CPayOffJournalName;
        ledgerJournalTableloc.initFromLedgerJournalName(ledgerJournalTableloc.JournalName);
        ledgerJournalTableloc.insert();

        select ledgerJournalTableExt
            where ledgerJournalTableExt.LedgerJournalTable == ledgerJournalTableloc.RecId;
        if(!ledgerJournalTableExt)
        {
            ledgerJournalTableExt.LedgerJournalTable = ledgerJournalTableloc.RecId;
            ledgerJournalTableExt.insert();
        }
        ttsCommit;
    }
    select ledgerJournalTab where ledgerJournalTab.journalnum == ledgerJournalTableloc.JournalNum;
   
   
    journal     = ledgerJournalTab.JournalNum;

    ttsBegin;

    ledgerJournalTransloc.initValue();
    ledgerJournalTransloc.initFromLedgerJournalTable_LT(ledgerJournalTableloc);
    numberSeq = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalName::find(salesParameters.CICPayOffJournalName).NumberSequenceTable).NumberSequence);

    ledgerJournalTransloc.voucher            = numberseq.voucher();
    ledgerJournalTransloc.TransDate          = _ledgerJournalTrans.TransDate;
    ledgerJournalTransloc.CurrencyCode       = _ledgerJournalTrans.CurrencyCode;
    ledgerJournalTransloc.Company            = curext();
    ledgerJournalTransloc.OffsetCompany      = _ledgerJournalTrans.OffsetCompany;
    ledgerJournalTransloc.AccountType        = LedgerJournalACType::Cust;
    ledgerJournalTransloc.JournalNum         = ledgerJournalTableloc.JournalNum;
    ledgerJournalTransloc.DefaultDimension   = _ledgerJournalTrans.DefaultDimension;

    select dim where dim.RecId == _ledgerJournalTrans.ledgerdimension;

    ledger = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(salesParameters.CPayOffLedger), _ledgerJournalTrans.DefaultDimension);

    ledgerJournalTransloc.LedgerDimension    = dim.RecId;
    ledgerJournalTransloc.OffsetLedgerDimension = ledger;
    LedgerAccountValue                       = dim.DisplayValue;
    MarkedInvoice                            = _ledgerJournalTrans.MarkedInvoice;
    ledgerJournalTransloc.Txt                = _ledgerJournalTrans.Txt;
    AmountCurCredit                          = _ledgerJournalTrans.AmountCurCredit;
    AmountCurDebit                           = _ledgerJournalTrans.AmountCurDebit;
    OffsetAccountType                        = LedgerJournalACType::Ledger;
    //journalTrans.clearField(fieldNum(ledgerJournalTrans,offsetLedgerDimension), false);

    //LedgerOffsetAccountValue                 = ledger;
    //AccountTypeId                            = 0001;
    //ledgerJournalTransloc.PaymMode           = formatcheck(10);
    //ledgerJournalTransloc.PaymReference      = formatcheck(11);
    /// ledgerJournalTransloc.CICDrawername      = 'ABC';
    ledgerJournalTransloc.Approved           = NoYes::Yes;
    ledgerJournalTransloc.Approver           = HcmWorker::userId2Worker(curUserId());
    ledgerJournalTransloc.Due                = ledgerJournalTransloc.TransDate;
    ledgerJournalTransloc.TransactionType    = LedgerTransType::Payment;

    if(LedgerAccountValue)
    {
        ledgerDim                              = DimensionStorage::getDynamicAccount(LedgerAccountValue, ledgerJournalTransloc.AccountType);
        ledgerJournalTransloc.LedgerDimension  = DimensionAttributeValueCombination::find(ledgerDim).Recid;
        if(LedgerJournalTransloc.AccountType == LedgerJournalACType::cust)
        {
            LedgerJournalTransloc.PostingProfile  = CustParameters::findByCompany(LedgerJournalTransloc.Company).PostingProfile;
        }
        if(LedgerJournalTransloc.AccountType == LedgerJournalACType::Vend)
        {
            LedgerJournalTransloc.PostingProfile  = VendParameters::find().PostingProfile;
        }
    }

    ledgerJournalTransloc.OffsetAccountType = OffsetAccountType;
    if(LedgerOffsetAccountValue)
    {
        if(ledgerJournalTransloc.OffsetAccountType == LedgerJournalACType::Ledger)
        {
            OffsetledgerDim                          = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(LedgerOffsetAccountValue), DefDimension);
            ledgerJournalTransloc.OffsetLedgerDimension = OffsetledgerDim;
        }
        else
        {
            OffsetledgerDim                           = DimensionStorage::getDynamicAccount(LedgerOffsetAccountValue, ledgerJournalTransloc.OffsetAccountType);
            ledgerJournalTransloc.OffsetLedgerDimension  = DimensionAttributeValueCombination::find(OffsetledgerDim).Recid;
        }
    }

    ledgerJournalTransloc.LineNum          = ledgerJournalTrans::lastLineNum(ledgerJournalTransloc.JournalNum) + 1;
    ledgerJournalTransloc.ExchRate         = Currency::exchRate(ledgerJournalTransloc.CurrencyCode, ledgerJournalTransloc.TransDate);
    ledgerJournalTransloc.insert();

    ledgerJournalTransExt.LedgerJournalTrans = ledgerJournalTransloc.RecId;
    ledgerJournalTransExt.AccountTypeId      = AccountTypeId;
    ledgerJournalTransExt.insert();

    ledgerJournalTransTaxExtensionIN.LedgerJournalTrans = ledgerJournalTransloc.RecId;
    ledgerJournalTransTaxExtensionIN.TaxInformation_IN  = TaxInformation_IN::findDefaultbyLocation(CompanyInfo::findByCompany_IN().PrimaryAddressLocation).RecId;
    ledgerJournalTransTaxExtensionIN.insert();

    if (ledgerJournalTransloc.AccountType == LedgerJournalACType::Cust)
    {
        value = this.customersettlement(_ledgerJournalTrans.MarkedInvoice,_ledgerJournalTrans.AmountCurCredit,dim.DisplayValue);
    }
    select count(RecId) from ledgerJournalTrans where ledgerJournalTrans.JournalNum == _ledgerJournalTrans.JournalNum;
    select ledgerJournalTable where ledgerJournalTable.JournalNum == journal;
    if (!value && ledgerJournalTrans.RecId==_row)
    {
        _LedgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,noYes::Yes);//(journalTable.ledgerJournalTable(),NoYes::Yes);
        _LedgerJournalCheckPost.run();
        ttscommit;
    }
}

//Payment of Journal-----------------------------------------------------(Method)

public void CICPayoffJournalImport(LedgerJournalTrans   _ledgerJournalTrans)
{
    AxLedgerJournalTable                        journalTable;
    AxLedgerJournalTrans                        journalTrans;
    container                                   _acctPattern;
    container                                   _offSetAcctPattern;
    LedgerJournalTable                          _LedgerJournalTable;
    LedgerJournalCheckPost                      _LedgerJournalCheckPost;
    DimensionAttributeValueCombination          dim;
    SalesParameters                             salesParameters;
    recid                                       ledger;
    ;

    JournalTable = new AxLedgerJournalTable();
    JournalTrans = new AxLedgerJournalTrans();

    select salesParameters;
    journalTable.parmJournalName(salesParameters.CPayOffJournalName);
    journalTable.save();

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(_ledgerJournalTrans.TransDate);
    journalTrans.parmCurrencyCode(_ledgerJournalTrans.CurrencyCode);
    journalTrans.parmAmountCurDebit(_ledgerJournalTrans.AmountCurDebit);
    journalTrans.parmAmountCurCredit(_ledgerJournalTrans.AmountCurCredit);
    journalTrans.parmDefaultDimension(_ledgerJournalTrans.DefaultDimension);
    journalTrans.parmInvoice(_ledgerJournalTrans.MarkedInvoice);
    journalTrans.parmTransactionType(LedgerTransType::GeneralJournal);

    journalTrans.parmAccountType(LedgerJournalACType::Cust);
    journalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);

    select dim where dim.RecId == _ledgerJournalTrans.ledgerdimension;

    journalTrans.parmLedgerDimension(dim.RecId);
    //journalTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimFromLedgerDim(_GeneralJournalAccountEntry.LedgerDimension));
    journalTrans.clearField(fieldNum(ledgerJournalTrans,offsetLedgerDimension), false);
    ledger = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(salesParameters.CICPayOffLedger), _ledgerJournalTrans.DefaultDimension);
    journalTrans.parmOffsetLedgerDimension(ledger);
    this.customersettlement(_ledgerJournalTrans.MarkedInvoice,_ledgerJournalTrans.AmountCurCredit,dim.DisplayValue);
    journalTrans.save();

    _LedgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
    _LedgerJournalCheckPost.run();

}

//Customer Settlement-------------------------------------------------------------(Method)
public boolean customerSettlement(InvoiceId   invoice, amountcur  Credit,CustAccount accountNum)
{
    custvendopentransmanager            manager;
    CustTransOpen                              CustTransOpen;
    CustTrans                                      CustTransExt;
    ExchangeRateHelper                    exchangeRateHelper;
    AmountCur                                   totalSettlement;
    boolean                                         value;

    select CustTransopen where CustTransOpen.AccountNum == accountNum
        join CustTransExt where CustTransExt.Invoice    == invoice
                             && CustTransExt.RecId      == CustTransopen.RefRecId
                             && CustTransExt.AccountNum == CustTransOpen.AccountNum;

    if(CustTransopen )//&& CustTransOpen.AmountCur >= Credit)
    {
        manager = custvendopentransmanager::construct(ledgerJournalTransloc);
        manager.updateTransMarked(CustTransOpen,true);

        exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(ledgerJournalTransloc.Company).RecId),ledgerJournalTransloc.CurrencyCode);
        totalSettlement    = SpecTransManager::getTotalSettleAmountForSpecReference(
                                ledgerJournalTransloc.Company,
                                ledgerJournalTransloc.TableId,
                                ledgerJournalTransloc.RecId,
                                ledgerJournalTransloc.CurrencyCode,
                                ledgerJournalTransloc.Company,
                                ledgerJournalTransloc.TransDate,
                                exchangeRateHelper.prepareExchangeRateForStorage(ledgerJournalTransloc.crossrate()));
        ttsBegin;
        ledgerJournalTransloc.selectForUpdate(true);
        //info(strFmt("%1" ,CustTransOpen.AmountCur));
        if (Credit <= abs(totalSettlement))
        {
            ledgerJournalTransloc.AmountCurCredit   = CustTransOpen.AmountCur;
        }
        ledgerJournalTransloc.SettleVoucher                = SettlementType::SelectedTransact;
        if (!ledgerJournalTransloc.Invoice)
        {
            ledgerJournalTransloc.MarkedInvoice             = invoice;
            ledgerJournalTransloc.DefaultDimension         = CustTransExt.DefaultDimension;
            ledgerJournalTransloc.OffsetDefaultDimension = CustTransExt.DefaultDimension;
        }
        ledgerJournalTransloc.doupdate();
        ttsCommit;
    }
    else
    {
        value = true;
        checkFailed("Please check the invoice amount.");
    }
    return value;
}


Tuesday, 2 October 2018

Attach documents or creates notes through X++ in Ax 2012

AX2012: Attach documents or creates notes through X++

Attach documents and create notes for a sales order after reading files from directories.

Documents can be attached to a sales order manually from the following button.








Code snippet to create notes or attach documents


 DocuRef             docuRef;
 DocuActionArchive   docuArchive;
 SalesTable          salesTable = SalesTable::find("SO00001");

 Filename            fileName = @"C\Temp\SalesOrder.docx";

 ttsbegin;

 // Code to create notes
 docuRef.TypeId       = 'Note';
 docuRef.Name         = "Sales order notes";
 docuRef.Notes  = "Checked Postcode: 2000, Select resident type";
 docuRef.Restriction  = DocuRestriction::External;
 docuRef.RefTableId   = tableNum(SalesTable);
 docuRef.RefRecId     = salesTable.RecId;
 docuRef.RefCompanyId = curext();
 docuRef.insert();

 //Code to attach file
 docuArchive = new DocuActionArchive();
 docuArchive.setType(docRef.TypeId);
 docuArchive.add(docuRef, fileName);

 ttscommit;

New Attachment Button on a new form AX 2012 R3 Without x++ coding

 New Attachment Button on a new form AX 2012 R3 Without x++ coding



Step 1. Open your form in AOT and Go to from Design node. 

Step 2. Add new button group under ActivePanTab. 

Step 3. Add new command button under this new button group. 

clip_image001 

Step 4. Set following properties of this button 

clip_image002 

Now you need to do one functional setup for this new customization 

Step 5: Open below from 
 Organization administration/SetUp-> Document Management -> Active Document Table 

Step 6: Add your table details here and click on Always enable. 

clip_image003 

Step 7: So its done now. 
Open your form and click on Attachment button , below form must open. 

clip_image006

Saturday, 29 September 2018

Create Number Sequence In Ax2012

Simple Steps To Create Number Sequence In Ax2012


           
Creating number seq:

 Hello Friends,
Today i want to describe about how to create number sequence in AX2012

It is same as like as we know in Ax2009 but small steps is added in AX2012.don't worry just follow the below steps simply we will get number sequence in AX2012.

We will Take a EDT name as "Car Id" and create in number sequence.For that first we should select a module for new number sequence for example project module.
                                   
steps:

1.  Create an edt : CarId .

     AOT >> Extended Data Types >> New  >> Properties >> Name  >> Car Id.

2. Write a code on lode module() on NumberSeqModuleProject

{
     datatype.parmDatatypeId(extendedTypeNum(Car Id));
     datatype.parmReferenceHelp(literalStr("@SYS334483"));
     datatype.parmWizardIsManual(NoYes::No);
     datatype.parmWizardIsChangeDownAllowed(NoYes::No);
     datatype.parmWizardIsChangeUpAllowed(NoYes::No);
     datatype.parmWizardHighest(999999);
     datatype.parmSortField(20);
     datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
     this.create(datatype);
}

3.Write a method on Projparameters Table

     client server static NumberSequenceReference numRefcarId()
{
     return NumberSeqReference::findReference(extendedTypeNum(car Id));
}

4.Write a job and run that

static void Carid(Args _args)
{
    NumberSeqModuleProject  NumberSeqModuleProject = new NumberSeqModuleProject();
    ;
    NumberSeqModuleProject.load();
}


5. Then run the wizard

   Organization Administration >> CommonForms >> Numbersequences>>Numbersequences>> Generate >> run the wizard.

6.Now we have to check the number sequence  is correctly working  for that write a job:

static void number(Args _args)
{
    NumberSeq  numberSeq;
    CarId num;
    ;
    numberSeq = NumberSeq::newGetNum(ProjParameters::numRefcarId());
    num = numberSeq.num();
    info(num);
}

  Run the above job.We will find the generated Number     sequence.                                                    .

7. Now we want that Number Sequence in form level(Car Table):

Declare the number sequence On Form Declaration:
 
public class FormRun extends ObjectRun
{
    NumberSeqFormHandler numberSeqFormHandler;

}

 8. Write the NumberSeqFormHandler() in form methods node.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(ProjParameters::numRefcarId      ().NumberSequenceId,
                                                             element,
                                                             CarTable_DS,
                                                             fieldNum(CarTable, Car Id)
                                                            );
    }
    return numberSeqFormHandler;
}


9.Write the close() on the form methods node.

void close()
{
    if (numberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super();
}

10. Then final add the below methods on data source methods node
Create()

void create(boolean append = false,
            boolean extern = false)  // If created externally
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(append);

    if (!extern)
    {
        element.numberSeqFormHandler().formMethodDataSourceCreate(true);
    }
}

Delete()

public void delete()
{
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}

Write()

public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Validate Write()

public boolean validateWrite()
{
    boolean         ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    if (ret)
    {
        CarTable.validateWrite();
    }
    return ret;
}

Link Active()

public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}

 Now our numberseqence is generated .

*** Set the field or Tabpage Allowedit property to No.
***Check the continues on wizard.

Friday, 28 September 2018

Import Invoice Journal in Ax 2012

void clicked()
{
    LedgerJournalTableExt            ledgerJournalTableExt;
    LedgerJournalTransExt            ledgerJournalTransExt;
    int                                             WrkShtNum;
    Dimension                                accountingRegion;
    ledgerJournalTable                  ledgerJournalTableloc;
    LedgerJournalTrans                 LedgerJournalTransloc;
    COMVariantType                     type;
    Name                                        Dim1,dim2,dim3,dim4,dim5,AccountNum,LedgerAccountValue,
                                                     LedgerOffsetAccountValue,OffsetAccount,dim6,dim7,offdim1,
                                                     formatValue,offdim3,offdim4,offdim5,offdim6,offdim7;
    LedgerJournalTransTaxExtensionIN    LedgerJournalTransTaxExtensionIN;
    LedgerDimensionAccount                   LedgerDim,DefDimension;
    LedgerDimensionAccount                   OffsetledgerDim;
    LedgerJournalACType                        OffsetAccountType;
    TransDate                                            transDate;
    CurrencyCode                                     currencyCode;
    NoYes                                                 noYes;
    numberSeq                                         numberSeq;

    name formatcheck(int val)
    {
        formatValue = "";
         switch(excelcells.item(row, val).value().variantType())
        {
            case COMVariantType::VT_BSTR:
                formatValue = strFmt("%1", excelcells.item(row, val).value().bStr());
                break;
            case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
                formatValue = strFmt("%1", any2int(excelcells.item(row, val).value().double()));
                break;
            case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
                formatValue = strFmt("%1", excelcells.item(row, val).value().int());
                break;
            case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
                formatValue = strFmt("%1", excelcells.item(row, val).value().uLong());
                break;
            case COMVariantType::VT_EMPTY:
                formatValue = '';
                break;
            default:
                throw error(strfmt("Issue in file coloum type.", excelcells.item(row+1, 1).value().variantType()));
        }
        return formatValue;
    }
    ;
    excelApp = SysExcelApplication::construct();
    startLengthyOperation();
    if(StrLTrim(StrRTrim(OpenExcelFile.text()))=="")
    {
        ExcelCells = NULL;
        excelWorksheet = NULL;
        excelApp.quit();
        throw error("Empty File Name");
    }
    else
    {
        WrkShtNum      = WorkSheetNum.value();
        excelApp.workbooks().open(OpenExcelFile.text());
        excelWorksheet = excelApp.worksheets().itemFromNum(WrkShtNum);
        excelCells     = excelWorksheet.cells();
        //Row = Element.FindFirstValidRowNum();
        Row=1;
        if(Row == 0)
        {
            ExcelCells = NULL;
            excelWorksheet = NULL;
            excelApp.quit();
            throw error("ERROR: Excel upload aborted...");
        }
        ttsBegin;
        ledgerJournalTableloc.JournalName = "APInv";
        ledgerJournalTableloc.initFromLedgerJournalName(ledgerJournalTableloc.JournalName);
        ledgerJournalTableloc.insert();

        select ledgerJournalTableExt
            where ledgerJournalTableExt.LedgerJournalTable == ledgerJournalTableloc.RecId;
        if(!ledgerJournalTableExt)
        {
            ledgerJournalTableExt.LedgerJournalTable = ledgerJournalTableloc.RecId;
            ledgerJournalTableExt.insert();
        }
        ttsCommit;
        do
        {
            try
            {
                ttsBegin;
                Row++;
                if(row > 1)
                {
                    transDate                             = excelcells.item(Row,1).value().date();
                    currencyCode                          = formatcheck(2);
                    if(transDate && currencyCode)
                    {
                        numberSeq = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalName::find(ledgerJournalTableloc.JournalName).NumberSequenceTable).NumberSequence);
                        LedgerJournalTransloc.voucher          = numberseq.voucher();
                        LedgerJournalTransloc.initValue();
                        LedgerJournalTransloc.initFromLedgerJournalTable_LT(ledgerJournalTable);
                        LedgerJournalTransloc.TransDate       = transDate ;
                        LedgerJournalTransloc.CurrencyCode    = currencyCode;
                        LedgerJournalTransloc.Company         = formatcheck(3);
                        LedgerJournalTransloc.AccountType     = str2enum(OffsetAccountType,formatcheck(4));
                        LedgerJournalTransloc.JournalNum      = LedgerJournalTableloc.JournalNum;
                        LedgerAccountValue                    = formatcheck(5);
                        Dim1                                  = formatcheck(6);
                        Dim2                                  = formatcheck(7);
                        Dim3                                  = formatcheck(8);
                        Dim4                                  = formatcheck(9);
                        Dim5                                  = formatcheck(10);
                        Dim6                                  = formatcheck(11);
                        DefDimension                          = element.DefaultDimension(Dim1, Dim2,Dim3,Dim4,Dim5,Dim6,"");
                        LedgerJournalTransloc.Invoice         = formatcheck(12);
                        LedgerJournalTransloc.TaxGroup        = formatcheck(13);
                        LedgerJournalTransloc.TaxItemGroup    = formatcheck(14);
                        LedgerJournalTransloc.Txt             = excelcells.item(Row,15).value().bStr();
                        LedgerJournalTransloc.AmountCurDebit  = excelcells.item(Row,16).value().double();
                        LedgerJournalTransloc.AmountCurCredit = excelcells.item(Row,17).value().double();
                        LedgerJournalTransloc.OffsetCompany   = formatcheck(18);
                        OffsetAccountType                     = str2enum(OffsetAccountType,formatcheck(19));
                        LedgerOffsetAccountValue              = formatcheck(20);
                        LedgerJournalTransloc.DocumentDate    = excelcells.item(Row,21).value().date();
                        LedgerJournalTransloc.Approved        = NoYes::Yes;
                        LedgerJournalTransloc.Approver        = HcmWorker::userId2Worker(curUserId());
                        LedgerJournalTransloc.Due             = LedgerJournalTransloc.TransDate;
                        LedgerJournalTransloc.TransactionType = LedgerTransType::Vend;

                        if(LedgerAccountValue)
                        {
                            if(LedgerJournalTransloc.AccountType == LedgerJournalACType::Ledger)
                            {
                                ledgerDim                           = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(LedgerAccountValue), DefDimension);
                                LedgerJournalTransloc.LedgerDimension  = DimensionAttributeValueCombination::find(ledgerDim).Recid;
                            }
                            else
                            {
                                LedgerJournalTransloc.DefaultDimension = DefDimension;

                                ledgerDim                           = DimensionStorage::getDynamicAccount(LedgerAccountValue, LedgerJournalTransloc.AccountType);
                                LedgerJournalTransloc.LedgerDimension  = DimensionAttributeValueCombination::find(ledgerDim).Recid;

                                if(LedgerJournalTransloc.AccountType == LedgerJournalACType::cust)
                                {
                                    LedgerJournalTransloc.PostingProfile  = CustParameters::findByCompany(LedgerJournalTransloc.Company).PostingProfile;
                                }
                                if(LedgerJournalTransloc.AccountType == LedgerJournalACType::Vend)
                                {
                                    LedgerJournalTransloc.PostingProfile  = VendParameters::find().PostingProfile;
                                }
                            }
                        }

                        LedgerJournalTransloc.OffsetAccountType = OffsetAccountType;

                        if(LedgerOffsetAccountValue)
                        {
                            if(LedgerJournalTransloc.OffsetAccountType == LedgerJournalACType::Ledger)
                            {
                                OffsetledgerDim                          = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(LedgerOffsetAccountValue), DefDimension);
                                LedgerJournalTransloc.OffsetLedgerDimension = OffsetledgerDim;
                            }
                            else
                            {
                                OffsetledgerDim                           = DimensionStorage::getDynamicAccount(LedgerOffsetAccountValue, LedgerJournalTransloc.OffsetAccountType);
                                LedgerJournalTransloc.OffsetLedgerDimension  = DimensionAttributeValueCombination::find(OffsetledgerDim).Recid;
                                LedgerJournalTransloc.OffsetDefaultDimension = DefDimension;
                            }
                        }

                        LedgerJournalTransloc.LineNum          = LedgerJournalTrans::lastLineNum(LedgerJournalTransloc.JournalNum) + 1;
                        LedgerJournalTransloc.ExchRate         = Currency::exchRate(LedgerJournalTransloc.CurrencyCode, LedgerJournalTransloc.TransDate);
                        LedgerJournalTransloc.insert();

                        ledgerJournalTransExt.LedgerJournalTrans = LedgerJournalTransloc.RecId;
                        ledgerJournalTransExt.insert();

                        ledgerJournalTransTaxExtensionIN.LedgerJournalTrans = LedgerJournalTransloc.RecId;
                        ledgerJournalTransTaxExtensionIN.TaxInformation_IN  = TaxInformation_IN::findDefaultbyLocation(CompanyInfo::findByCompany_IN().PrimaryAddressLocation).RecId;
                        ledgerJournalTransTaxExtensionIN.insert();
                    }
                }
                ttsCommit;
            }
            catch
            {
                Error(strfmt("Upload Failed in row %1", row));
            }
            type = excelcells.item(row+1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);

        info(strfmt("Journals %1 imported successfully",ledgerJournalTableloc.JournalNum));
        excelapp.quit();

    }
    endLengthyOperation();
    LedgerJournalTable_ds.executeQuery();
}

-------------------------------------------------------validated Excel-----------------------------------

int FindFirstValidRowNum()
{
    int R = 1;
    ;
    while(R < 28)
    {
        if(excelCells.item(R,1).value().bStr() == "TransDate"
        && excelCells.item(R,2).value().bStr() == "Currency"
        && excelCells.item(R,3).value().bStr() == "Company Code"
        && excelCells.item(R,4).value().bStr() == "AccountType"
        && excelCells.item(R,5).value().bStr() == "AccountNumber"
        && excelCells.item(R,6).value().bStr() == "ProfitCenter"
        && excelCells.item(R,7).value().bStr() == "Department"
        && excelCells.item(R,8).value().bStr() == "Offset account type"
        && excelCells.item(R,9).value().bStr() == "Offset account"
        && excelCells.item(R,10).value().bStr() == "Credit"
        && excelCells.item(R,11).value().bStr() == "Department"
        && excelCells.item(R,12).value().bStr() == "Divisons"
        && excelCells.item(R,13).value().bStr() == "BusinessUnit"
        && excelCells.item(R,14).value().bStr() == "Classes"
        && excelCells.item(R,15).value().bStr() == "Products"
        && excelCells.item(R,16).value().bStr() == "SubProducts"
        && excelCells.item(R,17).value().bStr() == "Invoice"
        && excelCells.item(R,18).value().bStr() == "Sales tax group"
        && excelCells.item(R,19).value().bStr() == "Item sales tax group"
        && excelCells.item(R,20).value().bStr() == "Description"
        && excelCells.item(R,21).value().bStr() == "Debit"
        && excelCells.item(R,22).value().bStr() == "Credit"
        && excelCells.item(R,23).value().bStr() == "Offset Company Code"
        && excelCells.item(R,24).value().bStr() == "OffsetAccount type"
        && excelCells.item(R,25).value().bStr() == "Offset account number"
        && excelCells.item(R,26).value().bStr() == "DocumentDate"
        && excelCells.item(R,27).value().bStr() == "Reverse"
        && excelCells.item(R,28).value().bStr() == "Reverse date")
            return R+1;

        R++;
    }
    error("ERROR: Not a valid ledger journal import excel file !!!");
    return 0;
}