Thursday, 1 August 2019

dynamic parameter and single parameter in ssrs Report ax 2012


dynamic parameter and single parameter in ssrs Report ax 2012

[DataContractAttribute,SysOperationContractProcessingAttribute(classStr(ALE_PositionVacantUIBuilder))]

class ALE_PositionVacantContract
{
    Ale_Period        period;
    ProjId      projId;
}

[DataMemberAttribute('period')]
public Ale_Period parmPeriod(Ale_Period _period = period)
{
    period = _period;
    return period;
}

.................................................................

class ALE_PositionVacantController extends SrsReportRunController
{
    #define.ReportName('ALE_PositionVacantReports.Report')
}

public static void main(Args _args)
{
    ALE_PositionVacantController controller = new ALE_PositionVacantController();
    ALE_PositionVacantContract contract;
    contract = new ALE_PositionVacantContract();

    controller.parmReportName(#ReportName);
    controller.parmShowDialog(true);
    controller.startOperation();
}

.....................................................................

class ALE_PositionVacantUIBuilder extends SrsReportDataContractUIBuilder
{
    ALE_PositionVacantContract      positionVacantContract;
    DialogField                     peroidDialogField;
}

..............................

public void build()
{
    positionVacantContract =  this.dataContractObject();

    peroidDialogField = this.addDialogField(methodstr(ALE_PositionVacantContract,parmPeriod), positionVacantContract);

}

............

public void getFromDialog()
{
    positionVacantContract = this.dataContractObject();
    super();
}

..........

private void peroidLookup(FormStringControl _formStringControl)
{
    Query                   query = new Query();
    QueryBuildDataSource    qbdsProjTable;
    SysTableLookup          sysTableLookup;

    // Create an instance of SysTableLookup with the current calling form control.
    sysTableLookup = SysTableLookup::newParameters(tableNum(Ale_PeriodMaster), _formStringControl);

    // Add fields to be shown in the lookup form.
    sysTableLookup.addLookupfield(fieldNum(Ale_PeriodMaster, Name), true);

    qbdsProjTable = query.addDataSource(tableNum(Ale_PeriodMaster));

    sysTableLookup.parmQuery(query);

    // Perform the lookup
    sysTableLookup.performFormLookup();

}

..............

public void postBuild()
{
    super();
    peroidDialogField = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(ALE_PositionVacantContract,parmPeriod));
    peroidDialogField.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(ALE_PositionVacantUIBuilder, peroidLookup), this);
    peroidDialogField.lookupButton(2);

}

.......

public void postRun()
{
    //super();
}

.......

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

[
    SRSReportQueryAttribute(querystr(ALE_PositionVacantProjTable)),
    SRSReportParameterAttribute(classstr(ALE_PositionVacantContract))
]
class ALE_PositionVacantDP extends SrsReportDataProviderPreProcessTempDB//SRSReportDataProviderBase //SrsReportDataProviderPreProcess //
{
    int                         serialNo;
    Ale_Period                  period;
    ALE_PositionVacantTmp      positionVacantTmp;
}

................

[SRSReportDataSetAttribute('ALE_PositionVacantTmp')]
public ALE_PositionVacantTmp getpositionVacantTmp()
{
    select * from positionVacantTmp;
    return positionVacantTmp;
}

..............

[SysEntryPointAttribute(true)]
public void processReport()
{
    ProjTable       projTable;
   
    ALE_PositionVacantContract contract = this.parmDataContract() as ALE_PositionVacantContract;
    Query q = this.parmQuery();
    QueryRun qr = new QueryRun(q);
    period = contract.parmPeriod();
    


    while (qr.next())
    {
        projTable = qr.get(tableNum(ProjTable));       

    }
}

Tuesday, 16 July 2019

Tax information in hours journal

Tax information in hours journal

/// <summary>
/// Checks and Inserts the current record into the <c>ProjJournalTransTaxExtensionIN</c> table.
/// </summary>
public void insert(boolean  _creditnNote = false)
{
    ProjJournalTrans    projJournalTrans;
    DirPartyLocation    dirPartyLocation;
    CustTable           custTable;
    // Start added by kiran
    CompanyInfo                 companyInfo;
    Dirpartytable               dirpartytable;
    DirPartyLocation            dirPartyLocationLoc;
    LogisticsLocation           logisticsLocation;
    TaxInformation_IN           taxInformation_IN;
    // End added by kiran Tax information update

    if (this.projJournalTrans)
    {
        select firstOnly projid from projJournalTrans
            where projJournalTrans.RecId == this.ProjJournalTrans;

        custTable                   = CustTable::find(ProjTable::find(ProjJournalTrans.ProjId).CustAccount);
        dirPartyLocation            = DirPartyLocation::findPrimaryPartyLocation(custTable.Party);
        this.CustomerLocation       = LogisticsLocation::find(dirPartyLocation.Location).RecId;
        this.CustomerTaxInformation = TaxInformation_IN::findDefaultbyLocation(this.CustomerLocation).RecId;
        // Start added by kiran 28 Mar 2019 - set Assessable value
        select PartyNumber from companyInfo where companyInfo.DataArea == curext()
                join dirpartytable where dirpartytable.PartyNumber == companyInfo.PartyNumber
                    join dirPartyLocationLoc where dirPartyLocationLoc.Party == dirpartytable.RecId
                        join logisticsLocation where logisticsLocation.RecId == dirPartyLocationLoc.Location
                            join taxInformation_IN where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId
                                && taxInformation_IN.IsPrimary == NoYes::Yes;
        this.TaxInformation = taxInformation_IN.RecId;// TaxRegistrationNumbers_IN::find(taxInformation_IN.GSTIN).RegistrationNumber;
        this.CompanyLocation = logisticsLocation.RecId;

        this.ServiceAccountingCodeTable = ServiceAccountingCodeTable_IN::find(ProjCategory::find(projJournalTrans.CategoryId).ServiceAccountingCodeTable_IN).RecId;
        if (_creditnNote == false)
        {
            if(ProjJournalName::find(ProjJournalTable::find(projJournalTrans.JournalId).JournalNameId).Ale_SalesPrice == NoYes::Yes || ProjJournalName::find(ProjJournalTable::find(projJournalTrans.JournalId).JournalNameId).Ale_VehiclePrice == NoYes::Yes)
            {
                this.AssessableValue        = projJournalTrans.Qty * projJournalTrans.SalesPrice;
            }
            else
            {
                this.AssessableValue        = projJournalTrans.Qty * projJournalTrans.CostPrice;
            }
        }
        // End added by kiran 28 Mar 2019

        super();

    }
}

Tuesday, 9 July 2019

Export voucher transactions/ split dimensions query

Query

class ALE_ExportVoucherTransToExcel extends RunBase
{
    QueryRun qr;

    DialogField dlgFromDate,dlgToDate;
    TransDate fromDate, toDate;

    #define.CurrentVersion(1)
    #localmacro.CurrentList

    #endmacro
}

......................................................................
public boolean canGoBatch()
{
    return true;
}

...........................................................
protected boolean canGoBatchJournal()
{
    return true;
}
/////////////////////////////////////////////

protected Object dialog()
{
    Dialog dialog;

    dialog = super();
    dialog.caption('Export voucher transactions to excel');

    return dialog;
}
--------------------------------------------------------------------

public boolean getFromDialog()
{
    boolean ret;

    ret = super();

    return ret;
}
--------------------------------------------------------------------
public void initParmDefault()
{
    Query query = new Query();
    QueryBuildRange queryBuildRange;
    QueryBuildDataSource queryBuildDataSource;
    ;
    queryBuildDataSource = query.addDataSource(tableNum(GeneralJournalEntry));
    queryBuildRange = queryBuildDataSource.addRange(FieldNum(GeneralJournalEntry,AccountingDate));

    qr = new SysQueryRun(query);

    super();
}
----------------------------------------------------------------------
public container pack()
{
    container pack = conNull();

    if (qr)
    {
        pack = qr.pack();
    }
    return [#CurrentVersion] + [pack];
}
-----------------------------------------------------------
public QueryRun queryRun()
{
    return qr;
}
--------------------------------------------------------
public void run()
{
    #AviFiles
    Args                                args;
    FormRun                             formRun;
    DimensionAttributeValueSetStorage    dimStorage;
    Counter                              i;
    DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
    DimensionAttribute                  dimAttr;
    GeneralJournalEntry                 generalJournalEntry;
    GeneralJournalEntry                 generalJournalEntryExcel;
    GeneralJournalAccountEntry          generalJournalAccountEntry;
    ALE_GeneralJournalAccountEntryExcel generalJournalAccountEntryExcel;
    DimensionValue                      bl,dept,project,worker,vehicle;


    SysOperationProgress    progressBar = new SysOperationProgress();
    args = new Args();

    delete_from generalJournalAccountEntryExcel;
    startLengthyOperation();
    while (qr.next())
    {
        generalJournalEntry = qr.get(tableNum(GeneralJournalEntry));
        try
        {
            while select generalJournalAccountEntry
                where generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId
            {
                bl = '';
                dept = '';
                project = '';
                vehicle ='';
                worker = '';

                while select DisplayValue from dimAttrView
                    where dimAttrView.ValueCombinationRecId == generalJournalAccountEntry.LedgerDimension
                    join BackingEntityType,Name from dimAttr
                        where dimAttr.RecId == dimAttrView.DimensionAttribute
                {
                    switch (dimAttr.Name)
                    {
                        case 'BusinessLine':
                            bl = dimAttrView.DisplayValue;
                            break;

                        case 'Department':
                            dept =  dimAttrView.DisplayValue;
                            break;

                        case 'Project':
                            project = dimAttrView.DisplayValue;
                            break;

                        case 'Vehicle':
                            vehicle = dimAttrView.DisplayValue;
                            break;

                        case 'Worker':
                            worker =  dimAttrView.DisplayValue;
                            break;
                    }
                }

                generalJournalAccountEntryExcel.JournalNumber       = generalJournalEntry.JournalNumber;
                generalJournalAccountEntryExcel.AccountingDate      = generalJournalEntry.AccountingDate;
                generalJournalAccountEntryExcel.SubledgerVoucher    = generalJournalEntry.SubledgerVoucher;
                generalJournalAccountEntryExcel.LedgerAccount       = generalJournalAccountEntry.LedgerAccount;

                generalJournalAccountEntryExcel.TransactionCurrencyCode     = generalJournalAccountEntry.TransactionCurrencyCode;
                generalJournalAccountEntryExcel.TransactionCurrencyAmount   = generalJournalAccountEntry.TransactionCurrencyAmount;
                generalJournalAccountEntryExcel.ReportingCurrencyAmount     = generalJournalAccountEntry.ReportingCurrencyAmount;
                generalJournalAccountEntryExcel.AccountingCurrencyAmount    = generalJournalAccountEntry.AccountingCurrencyAmount;
                generalJournalAccountEntryExcel.PostingType                 = generalJournalAccountEntry.PostingType;

                generalJournalAccountEntryExcel.BusinessLine    = bl;
                generalJournalAccountEntryExcel.Department      = dept;
                generalJournalAccountEntryExcel.Project         = project;
                generalJournalAccountEntryExcel.Vehicle         = vehicle;
                generalJournalAccountEntryExcel.Worker          = worker;
                generalJournalAccountEntryExcel.insert();

                progressBar.setCaption(strfmt("Exporting the voucher transactions"));
                progressBar.setAnimation(#AviUpdate);
                progressBar.setText(strfmt("Processing"));
            }

        }
        catch(Exception::Deadlock)
        {
            error('Caught an exception');
            retry;
        }
    }

    endLengthyOperation();
    args.name(formstr(ALE_VoucherTransExportToExcel));
    formRun = new FormRun(args);
    formRun.run();
    formRun.wait();
}
-------------------------------------------------------------------
public boolean runsImpersonated()
{
    return true;
}
------------------------------------------------------
public boolean showQueryValues()
{
    return true;
}
-----------------------------------
public boolean unpack(container _packedClass)
{
    boolean     ret         = false;
    int         version     = RunBase::getVersion(_packedClass);
    container   packedQuery = conNull();

    switch (version)
    {
        case #CurrentVersion:
            [version, packedQuery] = _packedClass;

            if (SysQuery::isPackedOk(packedQuery))
            {
                qr   = new QueryRun(packedQuery);
                ret         = true;
            }
            break;

        default:
            ret = false;
    }
    return ret;
}
---------------------------------------------------
static ClassDescription description()
{
    return "Export to excel";
}
-----------------------------------------------------------
public static void main(Args args)
{
    ALE_ExportVoucherTransToExcel exportVoucherTransToExcel = new ALE_ExportVoucherTransToExcel();

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

Export to excel in ax 2012 x++

Export to excel in ax 2012 x++

void clicked()
{
   /* #AviFiles
    DimensionAttributeValueSetStorage    dimStorage;
    Counter                              i;
    DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
    DimensionAttribute                  dimAttr;

    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    SysExcelCell            cell;
    SysExcelFont            font;
    int                     row,sleepCount = 1000;
    DimensionValue          bl,dept,project,worker,vehicle;
    GeneralJournalEntry     generalJournalEntryExcel;
    GeneralJournalAccountEntry generalJournalAccountEntryExcel;
    GeneralJournalAccountEntry generalJournalAccountEntryLoc;
    SysOperationProgress    progressBar = new SysOperationProgress();

    // intializing classes to export excel
    application = SysExcelApplication::construct();
    application.displayAlerts(false);
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');

    // Setting Header values
    cell = cells.item(1, 1);
    cell.value("Journal Number");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 2);
    cell.value("Date");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 3);
    cell.value("Voucher");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 4);
    cell.value("Ledger account");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 5);
    cell.value("Year Closed");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 6);
    cell.value("Currency code");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 7);
    cell.value("Transaction currency amount");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 8);
    cell.value("Reporting Currency amount");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,9);
    cell.value("Amount");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,10);
    cell.value("Posting layer");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,11);
    cell.value("Acknowledge");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,12);
    cell.value("Project");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,13);
    cell.value("worker");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,14);
    cell.value("vehicle");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,15);
    cell.value("Department");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1,16);
    cell.value("Business Line");
    font = cell.font();
    font.bold(true);

    try
    {
        row = 1;
        startLengthyOperation();
        while(queryRun.next())
        {
            generalJournalAccountEntryLoc = queryRun.get(tablenum(GeneralJournalAccountEntry));

            select generalJournalAccountEntryExcel
            join generalJournalEntryExcel where generalJournalAccountEntryExcel.GeneralJournalEntry == generalJournalEntryExcel.RecId
                && generalJournalAccountEntryExcel.RecId == generalJournalAccountEntryLoc.RecId;

                bl = '';
                dept = '';
                project = '';
                vehicle ='';
                worker = '';

                while select DisplayValue from dimAttrView
                    where dimAttrView.ValueCombinationRecId == generalJournalAccountEntryExcel.LedgerDimension
                    join BackingEntityType,Name from dimAttr
                        where dimAttr.RecId == dimAttrView.DimensionAttribute
                {
                    switch (dimAttr.Name)
                    {
                        case 'BusinessLine':
                            bl = dimAttrView.DisplayValue;
                            break;

                        case 'Department':
                            dept = "'" + dimAttrView.DisplayValue;
                            break;

                        case 'Project':
                            project = "'" + dimAttrView.DisplayValue;
                            break;

                        case 'Vehicle':
                            vehicle = dimAttrView.DisplayValue;
                            break;

                        case 'Worker':
                            worker = "'" + dimAttrView.DisplayValue;
                            break;
                    }
                }

                row++;
                cell = cells.item(row, 1);
                cell.value(generalJournalEntryExcel.JournalNumber);
                cell = cells.item(row, 2);
                cell.value(generalJournalEntryExcel.AccountingDate);
                cell = cells.item(row, 3);
                cell.value(generalJournalEntryExcel.SubledgerVoucher);
                cell = cells.item(row, 4);
                cell.value(generalJournalAccountEntryExcel.LedgerAccount);
                cell = cells.item(row, 5);
                cell.value(generalJournalEntryExcel.displayIsFiscalYearClosed());
                cell = cells.item(row, 6);
                cell.value(generalJournalAccountEntryExcel.TransactionCurrencyCode);
                cell = cells.item(row, 7);
                cell.value(generalJournalAccountEntryExcel.TransactionCurrencyAmount);
                cell = cells.item(row,8);
                cell.value(generalJournalAccountEntryExcel.ReportingCurrencyAmount);
                cell = cells.item(row, 9);
                cell.value(generalJournalAccountEntryExcel.AccountingCurrencyAmount);
                cell = cells.item(row, 10);
                cell.value(generalJournalEntryExcel.PostingLayer);
                cell = cells.item(row, 11);
                cell.value(generalJournalEntryExcel.ALE_AcknowledgeNumber);
                cell = cells.item(row, 12);
                cell.value(project);
                cell = cells.item(row, 13);
                cell.value(worker);
                cell = cells.item(row, 14);
                cell.value(vehicle);
                cell = cells.item(row, 15);
                cell.value(dept);
                cell = cells.item(row, 16);
                cell.value(bl);
            if(sleepCount == row)
            {
                sleepCount = sleepCount + 1000;
                sleep(10000);
            }
             infolog.yield();
            progressBar.setCaption(strfmt("Exporting the voucher transactions to excel",row));
            progressBar.setAnimation(#AviUpdate);
            progressBar.setText(strfmt("Processing %1 out of %2",row));
        }
        endLengthyOperation();
    }
    catch(Exception::Error)
    {
        throw(Exception::Error);
    }

    GeneralJournalAccountEntry_ds.reread();
    GeneralJournalAccountEntry_ds.research();

    application.visible(true);

    application.finalize();
    application = null;
   */
}

Thursday, 27 June 2019

Create hours journal from the Proj Listpage(posted transactions), using List,passing container

Create hours journal from the Proj Listpage(posted transactions), using List,passing container

void clicked()
{
    Args            args;
    MenuFunction    menuFunction;
    container       con;
    Str1260        listOfRecId;

    ProjPostTransView   projPostTransView;

    args = new Args();

    for(projPostTransView = ProjPostTransView_1_ds.getFirst(true) ? ProjPostTransView_1_ds.getFirst(true) : ProjPostTransView_1_ds.cursor(); projPostTransView; projPostTransView = ProjPostTransView_1_ds.getNext())
    {
        if(ProjTable::find(projPostTransView.ProjId).ParentId == '')
        {
            // storing recid of selected field in container
            con = conIns(con,1,projPostTransView.TransId);

            // converting container to string with comma separated
            listOfRecId = con2Str(con,',');
        }
    }
    args.parm(listOfRecId);
    if ( args.parm())
    {
        //Menu item GenerateJournalLInes from project
        menuFunction = new MenuFunction(menuitemActionStr(ALE_GenerateLinesFromProj), MenuItemType::Action);
        menuFunction.run(args);
    }
    ProjPostTransView_1_ds.reread();
    ProjPostTransView_1_ds.refresh();

}

................................................................

class ALE_GenerateJournalLinesFromProjPostedTr extends RunBase
{
    ProjPostTransView   projPostTransView;
    ProjJournalTrans    projJournalTransCheck;
    List                listOfRecid;
}

...........................................................................

public static void main(Args args)
{
    Str1260             listOfRecId;
    ProjPostTransView   projPostTransViewLoc;
    List           myListString = new List(Types::String);
    ALE_GenerateJournalLinesFromProjPostedTr generateJournalLinesFromProjPostedTr = new ALE_GenerateJournalLinesFromProjPostedTr();

    listOfRecId = args.parm();

    myListString = Global::strSplit(listOfRecId,',');
    generateJournalLinesFromProjPostedTr.getListOfRecId(myListString);

    generateJournalLinesFromProjPostedTr.run();

}

..............................................................................

public void run()
{

    ALE_GenerateJournalLinesFromProjPostedTr generateJournalLinesFromProjPostedTr = new ALE_GenerateJournalLinesFromProjPostedTr();

    try
    {
        generateJournalLinesFromProjPostedTr.createJournalLine(listOfRecId);

    }
    catch(Exception::Deadlock)
    {
        error('Caught an exception');
        retry;
    }

}

............................................................

public void getListOfRecId(List listOfRecIds)
{
    listOfRecid = listOfRecIds;
}

....................................................................

private void createJournalLine(List _listOfRecId)
{
    ProjJournalTable        projJournalTableLoc1,projJournalTable;
    ProjJournalTrans        projJournalTrans;
    ProjJournalTableData    projJournalTableData;
    ProjJournalTransData    projJournalTransData;
    int                     linescount;
    ProjTable               projTable;
    ProjPostTransView       projPostTransViewLoc;
    Str1260                 listOfRecIdLoc;
    ProjTransIdBase                projPostTransViewRecId;

    //projPostTransViewLoc = projPostTransViewV;
    List           listRecIdLoc = new List(Types::String);
    ListIterator   listIterator;

    ttsBegin;
    listRecIdLoc = _listOfRecId;
      projJournalTableData = JournalTableData::newTable(projJournalTable);
    projJournalTransData = projJournalTableData.journalStatic().newJournalTransData(projJournalTrans, projJournalTableData);
    // Init JournalTable -- header
    projJournalTable.clear();
    projJournalTable.JournalId      = projJournalTableData.nextJournalId();
    projJournalTable.JournalType    = ProjJournalType::Hour;
    projJournalTable.JournalNameId  = 'Hybrid';
    projJournalTable.initFromProjJournalName(ProjJournalName::find(projJournalTable.JournalNameId));
    projJournalTable.insert();
    // Init JournalTrans -- lines
    listIterator = new ListIterator(listRecIdLoc);
    while(listIterator.more())
    {
        projPostTransViewRecId = listIterator.value();
        select projPostTransViewLoc where projPostTransViewLoc.TransId == projPostTransViewRecId;
        while select projTable where projTable.ParentId == projPostTransViewLoc.ProjId
        {
            projJournalTableData.initFromJournalName(projJournalTableData.journalStatic().findJournalName(projJournalTable.JournalNameId));
            projJournalTrans.clear();
            projJournalTransData.initFromJournalTable();

            //projJournalTableData = JournalTableData::newTable(projJournalTableRevenueJournal);
            //projJournalTransData = projJournalTableData.journalStatic().newJournalTransData(projJournalTrans,projJournalTableData);

            projJournalTrans.JournalId = projJournalTable.JournalId;
            projJournalTrans.initValue();
            projJournalTrans.ProjId = projTable.ProjId;
            projJournalTrans.Worker = HcmWorker::findByPersonnelNumber('Blank').RecId;
            projJournalTrans.initFromProjTable( ProjTable::find(projPostTransViewLoc.ProjId));
            projJournalTrans.TransDate = projPostTransViewLoc.TransDate;
            projJournalTrans.LinePropertyId = ProjJournalName::find(projJournalTable.JournalNameId).ALE_LinePropertyId ;
            projJournalTrans.ProjTransDate = projJournalTrans.TransDate;

            projJournalTrans.Ale_WorkerName =  projPostTransViewLoc.WorkerName;//HcmWorker::find(projJournalTrans.Worker).name();// Added by somendra


            projJournalTrans.TransId        = '';

            projJournalTrans.CategoryId     = 'C-HYBRID-PRO';


            //projJournalTrans.setHourCostPrice();

            projJournalTrans.Qty = projPostTransViewLoc.Qty;
            if(projPostTransViewLoc.TotalCostAmountCur == 0)
            {
                projJournalTrans.CostPrice = (projPostTransViewLoc.TotalSalesAmountCur * projTable.Ale_HybridPercentage)/100;
            }
            else
            {
                projJournalTrans.CostPrice = (projPostTransViewLoc.TotalCostAmountCur * projTable.Ale_HybridPercentage)/100;
            }

            linescount++;
            projJournalTransData.create();

        }
       listIterator.next();
    }// List

        if(projJournalTrans.RecId)
        {
            select forUpdate projJournalTableLoc1 where projJournalTableLoc1.JournalId == projJournalTable.JournalId;

            projJournalTableLoc1.ProjQty    = projJournalTable.ProjQty ;
            projJournalTableLoc1.NumOfLines = projJournalTable.NumOfLines ;

            projJournalTableLoc1.update();

            info(strFmt('%1 -  %2 Journal lines has been created',projJournalTable.JournalId,linescount));
        }
        ttsCommit;



}

.....................................................

Saturday, 22 June 2019

upload beging balance ax 2012

upload beging balance ax 2012

class ALE_BegingingBalanceUpload extends RunBase
{
    JournalId               journalId;
}


...............................................................

public static void main(Args _args)
{
    JournalId           journalId;
    ProjJournalTable    projJournalTable;
    ALE_BegingingBalanceUpload  begingingBalanceUpload   = new ALE_BegingingBalanceUpload();
    projJournalTable = _args.record();
    journalId = projJournalTable.JournalId;
    begingingBalanceUpload.getJournalId(journalId);

        begingingBalanceUpload.DateImport();

}

............................................................................

public void getJournalId(JournalId journalIdB)
{
    journalId = journalIdB;
}

.................................................................

private RefRecId createCategoryDefaultDimensions(CategoryId _categoryId,DimensionValue _workerDim, DimensionValue _vehicleDim)
{
    DimensionAttributeValueSetStorage       dimStorage;
    RefRecId                                defaultDimensionLoc;
    ProjTable                               projTable;
    Counter                                 i;
    DimensionAttribute                      dimensionAttribute;
    DimensionAttributeValue                 dimensionAttributeValue;
    DimensionAttributeValueSetItem          dimensionAttributeValueSetItem;
    DimensionAttributeValueSetStorage       valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                        defaultDim;
    container                               conAttribute, conAttributeValue;
    DimensionValue                          ProjectcategoryItem,workerDim,vehicleDim;



    ProjectcategoryItem = _categoryId;
    workerDim = _workerDim;
    vehicleDim = _vehicleDim;

    conAttribute        = conNull();
    conAttributeValue   = conNull();



    conAttribute        = conIns(conAttribute,1,'ProjectcategoryItem');
    conAttributeValue   = conIns(conAttributeValue, 1, ProjectcategoryItem);
    conAttribute        = conIns(conAttribute,2,'Vehicle');
    conAttributeValue   = conIns(conAttributeValue, 2, vehicleDim);
    conAttribute        = conIns(conAttribute,3,'Worker');
    conAttributeValue   = conIns(conAttributeValue, 3, workerDim);

    for (i = 1; i <= conLen(conAttribute); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttribute,i));
        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }
        if (conPeek(conAttributeValue,i) != "")
        {
            dimensionAttributeValue =  dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conAttributeValue,i),false,true);
            valueSetStorage.addItem(dimensionAttributeValue);
        }

        defaultDimensionLoc = valueSetStorage.save();
    }
    return defaultDimensionLoc;
}

...............................................................................

private void DateImport()
{

    #File
    Dialog              dialog;
    Filename            filename;
    DialogField         dialogFilename;
    container           conFilter = ["Comma Seperated Value .txt ", "*.csv"];

    // start object creating
    ProjBegBalJournalTrans_CostSales    projBegBalJournalTrans_CostSales;
    BegBalProjTransTypeCost             projTransType;
    CategoryId                          categoryId;
    str                                 worker;
    Qty                                 qty;
    JournalId                           jId;
    //ProjId                              ProjId;
    ProjCostPriceCost                   costPrice;
    ProjSalesPriceCost                  salesPrice;
    ProjSalesCurrencyCode               currencyId;
    str                                 TransDate,ProjId;
    str                                 linePty;
    int                                 recCount;
    DimensionValue                      dimCat,dimWorker,dimVehical;
    ProjTable                           projTable;
    DimensionDefault                    dimension,catDim,workerDim,vehDim,dim1,dim2;
    DimAttributeProjCategory            dimAttributeProjCategory;
    ProjInvoiceProjId                   fundingId;
    // End  object creating
        ALE_BegingingBalanceUpload  begingingBalanceUpload   = new ALE_BegingingBalanceUpload();
    IO                   iO;
    FilenameOpen         filenameOpen;
    Container            record;
    boolean              first = true;
    dialog               = new dialog();


    dialog.caption("Select File For begining balance Import");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));

    //To filter the files while selecting
    dialog.filenameLookupFilter(conFilter);
    dialog.run();

    if(dialog.closedOk())
        {
         filename = dialogFileName.value();
        }

     iO = new CommaTextIo(filename,#IO_Read);

    if (! iO || iO.status() != IO_Status::Ok)
      {
        throw error("@SYS19358");
      }
    recCount = 0;
    ttsBegin;
    while (iO.status() == IO_Status::Ok)
    {
        record = iO.read();// To read file
        if (record)
        {
            if (first)  //To skip header
            {
                first = false;
            }
            else
            {
                qty = 0; salesPrice = 0; costPrice = 0;

                TransDate           =     conpeek(record, 1);
                ProjID              =     conpeek(record, 2);
                projTransType       =     conpeek(record, 3);
                categoryId          =     conpeek(record, 4);
                worker              =     conpeek(record, 5);
                qty                 =     conpeek(record, 6);
                costPrice           =     conpeek(record, 7);
                currencyId          =     conpeek(record, 8);
                salesPrice          =     conpeek(record, 9);
                linePty             =     conpeek(record, 10);
                fundingId             =     conpeek(record, 11);
                dimCat              =     conpeek(record, 12);
                dimWorker           =     conpeek(record, 13);
                dimVehical          =     conpeek(record, 14);


            projBegBalJournalTrans_CostSales.JournalId = journalId;
                projBegBalJournalTrans_CostSales.ProjTransDate = str2Date(TransDate,123);
                projBegBalJournalTrans_CostSales.ProjId= ProjID;
                projBegBalJournalTrans_CostSales.ProjTransType = projTransType;
                projBegBalJournalTrans_CostSales.ProjCategoryId = categoryId;
                projBegBalJournalTrans_CostSales.Quantity = qty;
                projBegBalJournalTrans_CostSales.ProjSalesCurrencyId = currencyId;
                projBegBalJournalTrans_CostSales.CostPrice = costPrice;
                projBegBalJournalTrans_CostSales.SalesPrice = salesPrice;
                projBegBalJournalTrans_CostSales.ProjLedgerCostStatus = 0;
                projBegBalJournalTrans_CostSales.ProjTransStatusPostedInvoiced = ProjTransStatusPostedInvoiced::Invoiced;
                projBegBalJournalTrans_CostSales.Worker = HcmWorker::findByPersonnelNumber(worker).RecId;
                projBegBalJournalTrans_CostSales.CostAmount = qty * costPrice;
                projBegBalJournalTrans_CostSales.ProjSalesAmount = qty * salesPrice;
                projBegBalJournalTrans_CostSales.LinePropertyId = linePty;
                projBegBalJournalTrans_CostSales.ProjFundingSource = ProjInvoiceTable::find(fundingId).RecId;
                projBegBalJournalTrans_CostSales.TransId           = ProjParameters::newTransId();

                vehDim = 0; workerDim = 0; catDim = 0;
                projTable = ProjTable::find(ProjID);
                if(projTable)
                {
                    dimension = begingingBalanceUpload.createCategoryDefaultDimensions(dimCat,dimWorker,dimVehical);
                    projBegBalJournalTrans_CostSales.DefaultDimension = projBegBalJournalTrans_CostSales.mergeDimension(projTable.DefaultDimension,dimension);
                }
                projBegBalJournalTrans_CostSales.insert();
                recCount++;
            }
        }
    }
    ttsCommit;
    info(strFmt(" %1 Record Insert successfully",recCount));
   }
........................................................

Sunday, 16 June 2019

AX Integration, Get data from SQL db to AX

AX Integration, Get data from SQL db to AX

//This class created by Ki  11-June-19 for PSA-AX integration
class PSA_ProjectMasterInboundProcess extends RunBaseBatch
{
    System.Data.OleDb.OleDbConnection objConn;
    System.Data.OleDb.OleDbCommand cmdSelect,cmdUpdate;
    System.Data.OleDb.OleDbDataReader reader,readerUpdate;
    container resultCon;
    str connectStr;
    ProjParameters projParameters;
    Map dimAttributeMap;
    ProjId  projID;
    Name    projName;

}

.............

public boolean canGoBatch()
{
    return true;

}
..........>

protected boolean canGoBatchJournal()
{
    return true;

}

........................>

public void createProject(container _c)
{
    boolean ret = true;
    ProjTable           newProjTable;
    ProjId              projIdNumSeq,projIdLoc;
    Name                projNameLoc;
    str                 projGroupLoc,projContractLoc,projTypeLoc,projStatusLoc,buLoc,deptLoc,custIdLoc,ccLoc,purposeLoc;
    int                 projTypeValue,projStatusValue;
    ProjTable           projTableLoc;
    Description         guidLoc;

    container           ledgerdimensionheader;
    DimensionDefault    dimensiondefaultheader;
    STG_ProjMaster  projMasterLoc;
    Struct structHdr = new Struct();

    NumberSeq projNumberSeq;
    CompanyInfo companyInfo = companyInfo::find();

    ;
    projNameLoc     = conpeek(_c, 1);
    projGroupLoc    = conpeek(_c, 2);
    projContractLoc = conpeek(_c, 3);
    projTypeLoc     = conpeek(_c, 4);
    projStatusLoc   = conpeek(_c, 5);
    buLoc           = conpeek(_c, 6);
    deptLoc         = conpeek(_c, 7);
    custIdLoc       = conpeek(_c, 8);
    ccLoc           = conpeek(_c, 9);
    purposeLoc      = conpeek(_c, 10);
    guidLoc         = conpeek(_c, 11);
    projIdLoc      = conpeek(_c, 12);


    projTableLoc = ProjTable::find(projIdLoc);
    if(!projTableLoc.ProjId)
    {
        projTypeValue = str2int(projTypeLoc);
        projStatusValue = str2int(projStatusLoc);

        projNumberSeq = NumberSeq::newGetNum(ProjParameters::numRefProjId(), true);

        if (projNumberSeq)
        {
            projIdNumSeq    = projNumberSeq.num();
        }
        projID                  = projIdNumSeq;
        newProjTable.ProjId     = projIdNumSeq;
        newProjTable.Name       = projNameLoc;
        newProjTable.ProjGroupId = projGroupLoc;
        newProjTable.ProjInvoiceProjId = projContractLoc;
        newProjTable.Type       = projTypeValue;
        newProjTable.Status     = projStatusValue;
        newProjTable.CustAccount = custIdLoc;

        if (buLoc && deptLoc && custIdLoc && ccLoc && purposeLoc)
        {
            structHdr.add('BusinessUnit', buLoc);
            structHdr.add('Department', deptLoc);
            structHdr.add('Customer', custIdLoc);
            structHdr.add('CostCenter', ccLoc);
            structHdr.add('Purpose', purposeLoc);
            structHdr.add('Project', projID);


            ledgerDimensionHeader += structHdr.fields();
            ledgerDimensionHeader += structHdr.fieldName(1);
            ledgerDimensionHeader += structHdr.valueIndex(1);
            ledgerDimensionHeader += structHdr.fieldName(2);
            ledgerDimensionHeader += structHdr.valueIndex(2);
            ledgerDimensionHeader += structHdr.fieldName(3);
            ledgerDimensionHeader += structHdr.valueIndex(3);
            ledgerDimensionHeader += structHdr.fieldName(4);
            ledgerDimensionHeader += structHdr.valueIndex(4);
            ledgerDimensionHeader += structHdr.fieldName(5);
            ledgerDimensionHeader += structHdr.valueIndex(5);
            ledgerDimensionHeader += structHdr.fieldName(6);
            ledgerDimensionHeader += structHdr.valueIndex(6);

            dimensionDefaultHeader = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimensionHeader);
        }

        newProjTable.DefaultDimension = dimensionDefaultHeader;
        newProjTable.insert();

        select forUpdate projMasterLoc where projMasterLoc.GUID == guidLoc;
        projMasterLoc.ProjId = newProjTable.ProjId;//projMasterLoc.ProjId = projID;
        projMasterLoc.update();
    }
    else
    {
        ttsBegin;
        select forUpdate newProjTable where newProjTable.ProjId ==   projTableLoc.ProjId;
        projTypeValue = str2int(projTypeLoc);
        projStatusValue = str2int(projStatusLoc);

        newProjTable.ProjGroupId = projGroupLoc;
        newProjTable.ProjInvoiceProjId = projContractLoc;
        newProjTable.Type       = projTypeValue;
        newProjTable.Status     = projStatusValue;
        newProjTable.CustAccount = custIdLoc;
        newProjTable.DefaultDimension = dimensionDefaultHeader;
        newProjTable.update();
        ttsCommit;

    }

}

...............................>

public Str1260 formatString(Str1260 _msg)
{
    str replace(str _source, str _what, str _with)
    {
        int found = 0;
        str target = _source;
        do
        {
            found = strscan(target, _what, found, strlen(target));
            if (found != 0)
            {
                target = strdel(target, found, strlen(_what));
                target = strins(target, _with, found);
                found += strlen(_with);
            }
        } while (found != 0);
        return target;
    }
    ;
    _msg = replace(_msg, '\n', '');
    _msg = replace(_msg, '\r', '');
    _msg = replace(_msg, '\t', '');
    _msg = replace(_msg, '\'', '');
    return _msg;

}

.............................>

public container pack()
{
    return conNull();

}

....................>

public container processProjTable(System.Data.OleDb.OleDbDataReader readerProject)
{
    int startLine = infologline(), currentLine, axStatus;
    int             i;
    Name            name;
    ProjId          projIDLoc,psaProjId;
    ProjGroupId     psaProjGroupId;
    CategoryId      psaCategoryId;
    ProjTable       projTable;
    str             projStatus,projType;
    AccountNum      custId;
    Description     psaGuid;

    str             businessUnit, department,msg,purpose,costCenter;
    ProjInvoiceProjId   contractId;
    STG_ProjMaster   projMaster;


    try
    {
        if (!readerProject.IsDBNull(0))
            psaProjGroupId = readerProject.GetString(0);
        else
            psaProjGroupId = "";

        if (!readerProject.IsDBNull(1))
            psaCategoryId = readerProject.GetString(1);
        else
            psaCategoryId = "";

        if (!readerProject.IsDBNull(2))
            contractId = readerProject.GetString(2);
        else
            contractId = "";

        if (!readerProject.IsDBNull(3))
            projType = readerProject.GetString(3);
        else
            projType = "";

        if (!readerProject.IsDBNull(4))
            projStatus = readerProject.GetString(4);
        else
            projStatus = "";

        if (!readerProject.IsDBNull(5))
            businessUnit = readerProject.GetString(5);
        else
            businessUnit = "";

        if (!readerProject.IsDBNull(6))
            department = readerProject.GetString(6);
        else
            department = "";

        if (!readerProject.IsDBNull(7))
            custId = readerProject.GetString(7);
        else
            custId = "";

        if (!readerProject.IsDBNull(8))
            costCenter = readerProject.GetString(8);
        else
            costCenter = "";

        if (!readerProject.IsDBNull(9))
            purpose = readerProject.GetString(9);
        else
            purpose = "";

        if (!readerProject.IsDBNull(10))
            name = readerProject.GetString(10);
        else
            name = "";

        if (!readerProject.IsDBNull(11))
            psaProjId = readerProject.GetString(11);
        else
            psaProjId = "";
        if (!readerProject.IsDBNull(12))
            psaGuid = readerProject.GetString(12);
        else
            psaGuid = "";
        //Insert in AX staging table-start

        if(ALE_STG_ProjMaster::findByGUID(psaGuid))
        {
            ttsBegin;
            select forUpdate projMaster where projMaster.GUID == psaGuid;
            projMaster.Name         = name;
            projMaster.ProjGroupId  = psaProjGroupId;
            projMaster.ProjContractId = contractId;
            projMaster.CategoryId   = psaCategoryId;
            projMaster.ALE_PRojType = any2str(projType);
            projMaster.BusinessUnit = businessUnit;
            projMaster.CostCentre   = costCenter;
            projMaster.Department   = department;
            projMaster.ProjStage    = projStatus;
            projMaster.CustAccount  = custId;
            projMaster.Purpose      = purpose;

            projMaster.update();
            ttsCommit;
        }
        else
        {
            projMaster.clear();
            projMaster.ProjId       = "";
            projMaster.Name         = name;
            projMaster.ProjGroupId  = psaProjGroupId;
            projMaster.ProjContractId = contractId;
            projMaster.CategoryId   = psaCategoryId;
            projMaster.ALE_PRojType = any2str(projType);
            projMaster.BusinessUnit = businessUnit;
            projMaster.CostCentre   = costCenter;
            projMaster.Department   = department;
            projMaster.ProjStage    = projStatus;
            projMaster.CustAccount  = custId;
            projMaster.Purpose      = purpose;
            projMaster.GUID         = psaGuid;

            projMaster.insert();
        }

        //Insert in AX staging table-start

        ttsbegin;

        // Project name
        if (readerProject.IsDBNull(10))
        {
            msg = 'Project name cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Project group
        if (readerProject.IsDBNull(0))
        {
            msg = 'Project group cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Project category
        if (readerProject.IsDBNull(1))
        {
            msg = 'Project category cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }
        // Project Contract Id
        if (readerProject.IsDBNull(2))
        {
            msg = 'Project Contract Id cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Project type
        if (readerProject.IsDBNull(3))
        {
            msg = 'Project type cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Project Status
        if (readerProject.IsDBNull(4))
        {
            msg = 'Project Status cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }
        // businessUnit
        if (readerProject.IsDBNull(5))
        {
            msg = 'Business Unit cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }
        // Department
        if (readerProject.IsDBNull(6))
        {
            msg = 'Department cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Customer Id
        if (readerProject.IsDBNull(7))
        {
            msg = ' Customer Id cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Cost Center
        if (readerProject.IsDBNull(8))
        {
            msg = 'Cost center cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        // Purpose
        if (readerProject.IsDBNull(9))
        {
            msg = 'Purpose cannot be null';
            ttsAbort;
            axStatus = -1;
            return [axStatus, msg];
        }

        //Financial dimension
        if (!readerProject.IsDBNull(5) && !readerProject.IsDBNull(6)
            && !readerProject.IsDBNull(7) && !readerProject.IsDBNull(8) && !readerProject.IsDBNull(9))
        {
            businessUnit = readerProject.GetString(5);
            department = readerProject.GetString(6);
            custId = readerProject.GetString(7);
            costCenter = readerProject.GetString(8);
            purpose = readerProject.GetString(9);

            if (custId == '0' || businessUnit == '0' || department == '0' ||  costCenter == '0' || purpose == '0' )
            {
                msg = 'Financial dimension value 0 is not valid';
                ttsAbort;
                axStatus = -1;
                return [axStatus, msg];
            }

            /*if (!DimensionFinancialTag::findByFinancialTagCategoryAndValue(5637144576,purpose) && purpose)
            {
                msg = strFmt("Business line %1 does not exists in purpose master.",purpose);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];

            }*/

            else if (!OMOperatingUnit::findNumber(businessUnit).OMOperatingUnitType == OMOperatingUnitType::OMBusinessUnit && businessUnit)
            {
                msg = strFmt("Business unit %1 does not exists in Business unit master.",businessUnit);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
            else if (!OMOperatingUnit::findNumber(department).OMOperatingUnitType == OMOperatingUnitType::OMDepartment && department)
            {
                msg = strFmt("Department %1 does not exists in department master.",department);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
            else if (!OMOperatingUnit::findNumber(costCenter).OMOperatingUnitType == OMOperatingUnitType::OMCostCenter && costCenter)
            {
                msg = strFmt("Department %1 does not exists in costCenter master.",costCenter);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }

            else if (!ProjCategory::find(psaCategoryId) && psaCategoryId)
            {
                msg = strFmt("Project category ID %1 does not exists in project Category master.",psaCategoryId);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
            else if (!ProjGroup::find(psaProjGroupId) && psaProjGroupId)
            {
                msg = strFmt("Project group ID %1 does not exists in project group master.",psaProjGroupId);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
            else if (!ProjInvoiceTable::find(contractId) && contractId)
            {
                msg = strFmt("Project contract ID %1 does not exists in project contract master.",contractId);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
            else if (!CustTable::find(custId) && custId)
            {
                msg = strFmt("Customer ID %1 does not exists in customer site master.",custId);
                axStatus = -1;
                ttsAbort;
                return [axStatus, msg];
            }
        }
        select forUpdate projTable
            where projTable.Name == name;

        if (!projMaster.ProjId)
        {
            this.createProject([name,psaProjGroupId,contractId,projType,projStatus,businessUnit,department,custId,costCenter,purpose,psaGuid]);
            axStatus = 2;
        }
        else
        {
            this.createProject([name,psaProjGroupId,contractId,projType,projStatus,businessUnit,department,custId,costCenter,purpose,psaGuid,projMaster.ProjId]);
            axStatus = 1;
        }

        msg = strFmt('Project created successfully ');
        ttscommit;

    }
    catch
    {
        ttsAbort;
        axStatus = -1;
        for (currentLine = startLine + 1; currentLine <= infologline(); currentLine++)
        {
            msg += infolog.text(currentLine);
        }
        msg = this.formatString(msg);

        infolog.clear();
    }
    return [axStatus, msg];

}

...............>

public void run()
{
    str datestr;
    //ProjMaster   projMasterUpdate;
    ProcessingStatus status;
    DataAreaId  psaCompanyId;
    string255 err;
    projParameters = ProjParameters::find();

    connectStr = 'Provider=SQLNCLI11;Integrated Security=SSPI;' +'Persist Security Info=False;Initial Catalog=' +
                    projParameters.ALE_PSA_StagingDBName + ';Data Source=' + projParameters.ALE_PSA_StagingDBServer + ';'+ 'User id=xxxxx;Password=xxxxx';
    try
    {
        objConn = new System.Data.OleDb.OleDbConnection(connectStr);
        objConn.Open();

        cmdSelect = objConn.CreateCommand();
        cmdSelect.set_CommandText('SELECT PM.ProjGroupID, PM.ProjCategoryId, PM.ProjContractID, PM.ProjType, PM.ProjStatus, PM.BUSINESSUNIT, PM.DEPARTMENT, PM.Customer, PM.CostCenter, PM.Purpose, PM.ProjName,PM.ProjId,PM.GUID,PM.CompanyId '+
                                    'FROM ProjMaster AS PM '+ 'WHERE PM.STATUS = 0');
        reader = cmdSelect.ExecuteReader();

        while (reader.Read())
        {
            psaCompanyId = reader.GetString(13);

            changeCompany(psaCompanyId)

            resultCon = this.processProjTable(reader);
            projName = reader.GetString(12);

            cmdUpdate = objConn.CreateCommand();
            cmdUpdate.set_CommandText(strFmt('UPDATE ProjMaster SET STATUS = %1,' + 'projId = ' + "'%2'" +', ERRORMESSAGE = ' + "'%3'" + 'WHERE GUID = ' + "'%4'",
                                                conPeek(resultCon, 1),projID, conPeek(resultCon, 2), projName));
            readerUpdate = cmdUpdate.ExecuteReader();

            if (conPeek(resultCon, 1) == 1)
                status = Ale_ProcessingStatus::Processed;
            else if (conPeek(resultCon, 1) == -1)
                status = Ale_ProcessingStatus::Error;
            else
                status = Ale_ProcessingStatus::Unprocessed;

            err = conPeek(resultCon, 2);

            //Update AX staging employee master-start
            //update_recordSet projMasterUpdate
                //setting processingstatus = status,ErrorMsg = err
            //where projMasterUpdate. == emplID
                //&& employeeMasterUpdate.ProcessingStatus == Ale_ProcessingStatus::Unprocessed;
            //Update AX staging employee master-end
        }
    }
    catch(Exception::Error)
    {
        error('An Exception has occurred');
    }

    if(objConn)
    {
        objConn.Close();
    }
}

.............>

public boolean runsImpersonated()
{
    return true;
}

.......................>

private void setDimensionAttribute()
{
   /* dimAttributeMap = new Map(Types::Integer, Types::Record);
    dimAttributeMap.insert(1, dimensionAttribute::findByName('BusinessLine'));
    dimAttributeMap.insert(2, dimensionAttribute::findByName('BusinessUnit'));
    dimAttributeMap.insert(3, dimensionAttribute::findByName('Department'));
    dimAttributeMap.insert(4, dimensionAttribute::findByName('Project'));
    dimAttributeMap.insert(5, dimensionAttribute::findByName('ProjectCategoryItem'));
    dimAttributeMap.insert(6, dimensionAttribute::findByName('Region'));
    dimAttributeMap.insert(7, dimensionAttribute::findByName('Site'));
    dimAttributeMap.insert(8, dimensionAttribute::findByName('Worker'));*/
}
..............>

public boolean unpack(container _packedClass)
{
    return true;
}

...............................>

static ClassDescription description()
{
    return "Project master inbound process";
}

>>>>>>>>>>>>>>>>>>

public static void main(Args args)
{
    ProjectMasterInboundProcess projectMasterInboundProcess = new  ProjectMasterInboundProcess();;

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