Tuesday, 7 January 2014

Get Opening Balance in ax 2009 through X++

real getOpeningBalance(LedgerAccount _accountNum)

{

    DimensionCriteria   dimensionCriteriaEmpty;
    Transdate           periodEnd;
    transdate periodStart = LedgerPeriod::findOpeningDate(fromDate);
    LedgerBalanceSum_CurrentMST   ledgerBalance;
    ;
    periodEnd = fromDate - 1;

    ledgerBalance= new LedgerBalanceSum_CurrentMST(periodStart,
                                                   periodEnd,
                                                   dimensionCriteriaEmpty,
                                                   NoYes::Yes,
                                                   Noyes::Yes,
                                                   NoYes::Yes,
                                                   OperationsTax::Current,
                                                   DebCredProposal::None,
                                                   NoYes::Yes,
                                                   NoYes::Yes);
    return ledgerBalance.balance(_accountNum);


}

Call one form to Other form in ax 2009 through X++

void click()

{
    Args     args;
    Formrun  formrun;
    ;
    super();
    args =new Args(formstr(III_secondform))
    args.caller(element);
    args.record(III_customer);
    args.parm(org.text)
    formrun = classfactory.formrunclass(args);
    formrun.init();
    formrun.run();
    formrun.wait();
    formrun.detach();
}

second form int method :-

public void int()
{
   III_Customer  c;
   ;
   super();
   if(!element.args().caller())
   {
      throw error("form cannot be open directly");
   }
   c = element.args().record();
   name.text(c.custname);

}

Complex Dynamic Query with text file in ax 2012 through X++

private void createQuery()

{
    Query                       query = new Query();
    QueryBuildDataSource        qbdsCUstTable;
    QueryBuildDataSource        qbdsAccType;
    QueryBuildDataSource        qbdsConRes;
    QueryBuildDataSource        qbdsConnection;
    QueryBuildDataSource        qbdsConStatus;
    QueryBuildDataSource        qbdsDevice;
    QueryBuildDataSource        qbdsConfigHist;
    QueryBuildDataSource        qbdsDeviceStatus;
    QueryBuildDataSource        qbdsFreqHist;
    QueryRun                    queryRn;
    Name                        tmpName;
    FcsDateTime                 tmpDateTime = FcsDateTimeAPI::dateNow();
    McsConfigurationHistory     configHistLocal;
    FcsDateTime                 startDateLocal,endDateLocal;
    str                         seprator = McsParameters::find().FedSBMDownloadSeperator;
    McsFedOMDivision            division;
    McsFedOMSubDivision         subDivision;
    McsFedOMSection             section;
    McsEmCalcCalculatedConsumption  calCOnsumption;
    McsConnectionMember         conMember;

    ;

    qbdsCUstTable = query.addDataSource(tableNum(CustTable));
    //.............added by aslam
    if(DivisionId)
    {
          qbdsCUstTable.addRange(fieldNum(CustTable,FedDivisionId)).value(DivisionId);
    }
    if(SubDivId)
    {
          qbdsCUstTable.addRange(fieldNum(CustTable,FedSubDivId)).value(SubDivId);
    }
    if(SectionId)
    {
          qbdsCUstTable.addRange(fieldNum(CustTable,FedSectionId)).value(SectionId);
    }
    if(cycleCode)
    {
          qbdsCUstTable.addRange(fieldNum(CustTable,FedCycleCode)).value(cycleCode);
    }
    //...............end by aslam
    qbdsAccType = qbdsCUstTable.addDataSource(tableNum(McsAccountTypeHistory));
    qbdsAccType.addLink(fieldNum(custTable,AccountNum),fieldNum(McsAccountTypeHistory,CustomerId));
   // qbdsAccType.joinMode(JoinMode::InnerJoin);
    qbdsAccType.addRange(fieldNum(McsAccountTypeHistory,AccountType)).value(queryValue(McsGlobal::getDefaultAccountTypeMainRelation()));
    qbdsAccType.addRange(fieldNum(McsAccountTypeHistory,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));

    qbdsConRes = qbdsAccType.addDataSource(tableNum(McsConnectionResponsible));
    qbdsConRes.addLink(fieldNum(McsAccountTypeHistory,Id),fieldNum(McsConnectionResponsible,AccountTypeHistoryId));
    qbdsConRes.addRange(fieldNum(McsConnectionResponsible,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));
    //qbdsConRes.joinMode(JoinMode::InnerJoin);

    qbdsConnection = qbdsConRes.addDataSource(tableNum(McsConnection));
    qbdsConnection.addLink(fieldNum(McsConnectionResponsible,ConnectionId),fieldNum(McsConnection,Id));
    //qbdsConnection.addOrderByField(fieldNum(McsConnection,Id),SortOrder::Ascending);
    //qbdsConnection.joinMode(JoinMode::InnerJoin);

    qbdsConStatus = qbdsConnection.addDataSource(tableNum(McsConnectionStatusHistory));
    qbdsConStatus.addLink(fieldNum(McsConnection,Id),fieldNum(McsConnectionStatusHistory,ConnectionId));
    qbdsConStatus.addRange(fieldNum(McsConnectionStatusHistory,ConnectionStatus)).value(queryValue(McsStatuses::Active));
    qbdsConStatus.addRange(fieldNum(McsConnectionStatusHistory,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));
    //qbdsConStatus.joinMode(JoinMode::InnerJoin);

    /*qbdsFreqHist = qbdsConnection.addDataSource(tableNum(McsCmBilBilFrequencyHistory));
    qbdsFreqHist.addLink(fieldNum(McsConnection,Id),fieldNum(McsCmBilBilFrequencyHistory,Connectionid));
    qbdsFreqHist.addRange(fieldNum(McsCmBilBilFrequencyHistory,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));
    qbdsFreqHist.addRange(fieldNum(McsCmBilBilFrequencyHistory,DataAreaId)).value(queryValue('((LastBillingDate < EndDate) || (EndDate == 0))'));
    //qbdsFreqHist.addRange(fieldNum(McsCmBilBilFrequencyHistory,NextBillingDate)).value(queryValue(FcsDateTimeAPI::addDayLocal(this.parmEndDate(),1)));
    qbdsFreqHist.addSortField(fieldNum(McsCmBilBilFrequencyHistory,StartDate),SortOrder::Ascending);
    qbdsFreqHist.joinMode(JoinMode::InnerJoin);*/

    qbdsConfigHist = qbdsConStatus.addDataSource(tableNum(McsConfigurationHistory));
    qbdsConfigHist.addLink(fieldNum(McsConnectionStatusHistory,ConnectionId),fieldNum(McsConfigurationHistory,ConnectionId));
    qbdsConfigHist.addRange(fieldNum(McsConfigurationHistory,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));
    //qbdsConfigHist.joinMode(JoinMode::InnerJoin);

 qbdsDevice = qbdsConfigHist.addDataSource(tableNum(McsMeterDevice));
    qbdsDevice.addLink(fieldNum(McsConfigurationHistory,MeterDeviceId),fieldNum(McsMeterDevice,Id));
    qbdsDevice.addRange(fieldNum(McsMeterDevice,FedPhase)).value(queryValue(McsFedPhases::ThreePhase));

    //qbdsDevice.joinMode(JoinMode::InnerJoin);

    qbdsDeviceStatus = qbdsDevice.addDataSource(tableNum(McsMeterDeviceStatusHistory));
    qbdsDeviceStatus.addLink(fieldNum(McsMeterDevice,Id),fieldNum(McsMeterDeviceStatusHistory,   MeterDeviceId));
    qbdsDeviceStatus.addRange(fieldNum(McsMeterDeviceStatusHistory,MeterDeviceStatus)).value(queryValue(McsStatuses::Active));
    qbdsDeviceStatus.addRange(fieldNum(McsMeterDeviceStatusHistory,ValidUntilDate)).value(queryValue(FcsDateTimeAPI::DateNull()));

    //qbdsDeviceStatus.joinMode(JoinMode::InnerJoin);




    queryRn = new QueryRun(query);

    totalRecords = SysQuery::countLoops(queryRn);
    progress.setCaption("Downlaod Customer");

    progress.setAnimation(#aviUpdate);

    progress.setTotal(totalRecords);


    progress.update(true);
    totalRecords = 0;
    while (queryRn.next())
    {
        //custTable.clear();
        //meterDevice.clear();
        //Connection.clear();
        //configHistLocal.clear();

        custTable = queryRn.get(tableNum(CustTable));
        meterDevice = queryRn.get(tableNum(McsMeterDevice));
        Connection  = queryRn.get(tableNum(McsConnection));
        configHistLocal = queryRn.get(tableNum(McsConfigurationHistory));
        progress.setText("Exporting Customer " + custTable.name());
        progress.update(true);
        //Consumer No. ---1
        tb.setText(tb.getText() + strFmt("%1%2",custTable.McsExternalID1,seprator));
        //Old K Number----2
        tb.setText(tb.getText() + strfmt("%1%2",custTable.McsExternalId3,seprator));
        //Tariff Code ----3
        tb.setText(tb.getText() + strfmt("%1%2",custTable.CustGroup,seprator));
        //Meter Serial Number---4
        tb.setText(tb.getText() + strfmt("%1%2",meterDevice.MeterDeviceSerialNumber,seprator));
        //Consumer Name---5
        tb.setText(tb.getText() + strfmt("%1%2",subStr(custTable.name(),1,20),seprator));
        //Address---6
        tb.setText(tb.getText() + strfmt("%1%2",subStr(custTable.address(),1,20),seprator));
        //Cycle Display Code----7
        tb.setText(tb.getText() + strfmt("%1%2",custTable.FedCycleCode,seprator));
        //Route Nbr---8
        tb.setText(tb.getText() + strfmt("%1%2",custTable.FedRouteNbr,seprator));

        //Division---9
        division.clear();
        select DisplayCode from division
            where division.DivisionId == custTable.FedDivisionId;

        tb.setText(tb.getText() + strfmt("%1%2",division.DisplayCode,seprator));

        //SubDivision---10
        subDivision.clear();
        select DisplayCode from subDivision
            where subDivision.SubDivId == custTable.FedSubDivId;
        tb.setText(tb.getText() + strfmt("%1%2",subDivision.DisplayCode,seprator));

        //section---11
        section.clear();
        select DisplayCode from section
            where section.SectionId == custTable.FedSectionId;
        tb.setText(tb.getText() + strfmt("%1%2",section.DisplayCode,seprator));

        //BillMonth---12
        select EndDate from calCOnsumption
        order by EndDate desc
        exists join conMember
            where conMember.Id == calCOnsumption.ConnectionMemberId
            && calCOnsumption.ValidUntilDate == 0
            && conMember.ValidUntilDate == 0
            && conMember.ConnectionId == Connection.Id
            && conMember.ConnectionMemberType == McsConnectionMemberTypes::mmrcons;

        tb.setText(tb.getText() + strfmt("%1",date2str(FcsDateTimeAPI::convertToDateLocal(    calCOnsumption.EndDate),123,0,0,3,3,2)));
       tb.setText(tb.getText() + strfmt("\n"));
        progress.incCount();
        progress.update(true);
    }

}

Find On Hand through X++ in ax 2009


static void findOnHand(Args _args)

InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
;

// take a sample item for testing
itemid = "20 MM RMC";

// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "GW";

//Set the flag for the selected dimensions as active.
inventDimParm.initFromInventDim(inventDim);

//initialize the inventonhand with item,dimension and dim paramter
inventOnHand = InventOnHand::newParameters(itemid, inventDim, inventDimParm);

// Retrieve the onhand info
info(strfmt("Available Physical: %1", inventOnhand.availPhysical()));
info(strfmt("Physical Invent: %1", inventOnhand.physicalInvent()));
info(strfmt("On order: %1", inventOnhand.onOrder()));

}

Monday, 6 January 2014

Overriding vs. Overloading in ax 2012


Overloading is where there is more than one method with the same name, but the methods have different signatures (return type or parameter lists or both).

Overriding is where the super class's implementation of a method is altered by the subclass's implementation of the method, but the signatures of both methods are the same.

X++ supports overriding, but it does not support overloading.

Creating a delete action in ax 2012


None:-      No action will take place on related records in the RentalTable when you delete a record in the CarTable.

Cascade:- All records in RentalTable related to the record being deleted in CarTable will also be deleted.

Restricted:- The user will get a warning saying that the record in the CarTable cannot be deleted because transactions exist in table RentalTable. The user will be unable to delete the record in CarTable if one or more related records exist in the RentalTable.

Cascade + Restricted:- This option is used when deleting records through more than two levels. Let's say that another table existed that had a cascade delete action against CarTable and the CarTable had a
Cascade + Restriced delete action against Rental Table. If the record in the top level table was about to be deleted it would also delete the related records in CarTable. In turn, all the records in RentalTable related to the records being deleted from CarTable would also be deleted. If only a record in CarTable was about to
be deleted, the user would get the same message as when using the Restricted method.

Dynamic query in ax 2012


static void queryRunRentalCarListAOT(Args _args)
{
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
CarTable carTable;
RentalTable rentalTable;
;
query = new Query(querystr(RentalCarList));
queryBuildDataSource = query.dataSourceTable(tablenum(CarTable));
queryBuildRange = queryBuildDataSource.findRange(fieldnum(CarTable, ModelYear));
queryBuildRange.value("2008..");
queryRun = new QueryRun(query);
while (queryRun.next())
{
carTable = queryRun.get(tablenum(CarTable));
rentalTable = queryRun.get(tablenum(RentalTable));
info (strfmt("CarId %1, RentalId %2", carTable.CarId, rentalTable.RentalId));
}
}


static void queryRunRentalCarList(Args _args)
{
Query query;
QueryBuildDataSource queryBuildDataSource1,
queryBuildDataSource2;
QueryBuildRange queryBuildRange;
QueryBuildLink queryBuildLink;
QueryRun queryRun;
CarTable carTable;
RentalTable rentalTable;
;
query = new Query();
queryBuildDataSource1 = query.addDataSource(tablenum(CarTable));
queryBuildRange = queryBuildDataSource1.addRange(fieldnum(CarTable, ModelYear));
queryBuildRange.value("2008..");
// Add the second datasource to the first data source
queryBuildDataSource2 = queryBuildDataSource1.addDataSource(tablenum(RentalTable));
queryBuildLink = queryBuildDataSource2.addLink(fieldnum(CarTable,CarId),fieldnum(RentalTable, CarId));
queryRun = new QueryRun(query);
// Loop through all the records returned by the query
while (queryRun.next())
{
carTable = queryRun.get(tablenum(CarTable));
rentalTable = queryRun.get(tablenum(RentalTable));
info (strfmt("CarId %1, RentalId %2", carTable.CarId,
rentalTable.RentalId));
}
}

SQL/SSRS Interview questions I thought of blogging some SQL/SSRS interview questions.

Below are some. I will add more, when I complete the compilation 1. What is OLTP(Online Transaction Processing)? OLTP stands ...