Tuesday, 7 January 2014

Field1_1_modified and Fld_7_lookup on the dilaog through X++ ax 2009


public void dialogPostRun(DialogRunbase _dialog)
{
    super(_dialog);

    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

Note, that in the code above the RunBase class itself is used as event handler (by passing this to the controlMethodOverloadObject() method), but it is possible to create a separate class for handling events.

Afterwards event handlers can be created as method with specific name: _. Control name can be found in the dialog user setup. For example, the following method will handle modify event of the first field control on the dialog:
public void fld1_1_modified()
{
    Object control;

    control = dialog.formRun().controlCallingMethod();

    if(control.modified())
    {
        info(“Modified triggered!”);
    }
 
public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
    DialogRunBase   dialog;
    ;

    dialog = super(_dialog, true);

    dialog.caption('@RID2885');

    dfItem = dialog.addField(typeid(ItemId));
    dfInventLoc = dialog.addField(typeid(InventLocationId));
    dfReplaceCost = dialog.addField(typeid(PdsCost));
    dfItemConfig = dialog.addField(typeid(ConfigId));
    dfColorId = dialog.addField(typeid(InventColorId), '@RID101');

    return dialog;
}
void Fld_7_lookup()

{

    Formrun fr = this.dialogModify().parmDialog();

    Object control = fr.controlCallingMethod();    

    ;

    ConfigTable::lookupConfigIdSimple(control, dfItem.value());    

}
public void dialogPostRun(DialogRunbase _dialog)

{

    ;

     super(_dialog);

    **_dialog.formRun().controlMethodOverload(true);** // Causes Stack Trace error

    _dialog.formRun().controlMethodOverloadObject(this);       

}

Mayby you should call super(_dialog) last in the dialogPostRun method.
Here is an example code for overriding the modified method. Maybe lookup has the same requirements:
public void dialogPostRun(DialogRunbase _dialog)
{
// Must be overriden to enable overriding modified method
;
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);

    super(_dialog);
}
And for the custom method:
boolean Fld2_1_modified()
{
    FormStringControl c = dialog.formrun().controlCallingMethod();
    boolean ret;
    ;

    ret = c.modified(); // Super() Call the FormControl ->modified

    dlgCustomField.value(MyClass::someMethod(dlgCustomField.value())); // example

    return ret;
}
public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
    DialogRunBase   dialog;
    ;

    dialog = super(_dialog, true);

    dialog.caption('@RID2885');

    dfItem = dialog.addField(typeid(ItemId));
    dfInventLoc = dialog.addField(typeid(InventLocationId));
    dfReplaceCost = dialog.addField(typeid(PdsCost));
    dfItemConfig = dialog.addField(typeid(ConfigId));
    dfColorId = dialog.addField(typeid(InventColorId), '@RID101');

    return dialog;
}
Here's the call to the lookup():
void Fld_7_lookup()
{
    Formrun fr = this.dialogModify().parmDialog();
    Object control = fr.controlCallingMethod();
    ;

    ConfigTable::lookupConfigIdSimple(control, dfItem.value());
}
And this is where it keeps getting the Stack Trace error:
public void dialogPostRun(DialogRunbase _dialog)
{
    ;
     super(_dialog);
    **_dialog.formRun().controlMethodOverload(true);** // Causes Stack Trace error
    _dialog.formRun().controlMethodOverloadObject(this);   
}
Mayby you should call super(_dialog) last in the dialogPostRun method.

Here is an example code for overriding the modified method. Maybe lookup has the same requirements:
public void dialogPostRun(DialogRunbase _dialog)
{
// Must be overriden to enable overriding modified method
;
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);

    super(_dialog);
}
And for the custom method:
boolean Fld2_1_modified()
{
    FormStringControl c = dialog.formrun().controlCallingMethod();
    boolean ret;
    ;

    ret = c.modified(); // Super() Call the FormControl ->modified

    dlgCustomField.value(MyClass::someMethod(dlgCustomField.value())); // example

    return ret;
}
public void dialogPostRun(DialogRunbase _dialog)
{
    super(_dialog);

    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

Note, that in the code above the RunBase class itself is used as event handler (by passing this to the controlMethodOverloadObject() method), but it is possible to create a separate class for handling events.

Afterwards event handlers can be created as method with specific name: _. Control name can be found in the dialog user setup. For example, the following method will handle modify event of the first field control on the dialog:
public void fld1_1_modified()
{
    Object control;

    control = dialog.formRun().controlCallingMethod();

    if(control.modified())
    {
        info(“Modified triggered!”);
    }

fld1_1_modified and Fld_7_lookup on the dilaog through X++ ax 2009


public void dialogPostRun(DialogRunbase _dialog)
{
    super(_dialog);

    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

Note, that in the code above the RunBase class itself is used as event handler (by passing this to the controlMethodOverloadObject() method), but it is possible to create a separate class for handling events.

Afterwards event handlers can be created as method with specific name: _. Control name can be found in the dialog user setup. For example, the following method will handle modify event of the first field control on the dialog:
public void fld1_1_modified()
{
    Object control;

    control = dialog.formRun().controlCallingMethod();

    if(control.modified())
    {
        info(“Modified triggered!”);
    }
 
public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
    DialogRunBase   dialog;
    ;

    dialog = super(_dialog, true);

    dialog.caption('@RID2885');

    dfItem = dialog.addField(typeid(ItemId));
    dfInventLoc = dialog.addField(typeid(InventLocationId));
    dfReplaceCost = dialog.addField(typeid(PdsCost));
    dfItemConfig = dialog.addField(typeid(ConfigId));
    dfColorId = dialog.addField(typeid(InventColorId), '@RID101');

    return dialog;
}
void Fld_7_lookup()

{

    Formrun fr = this.dialogModify().parmDialog();

    Object control = fr.controlCallingMethod();    

    ;

    ConfigTable::lookupConfigIdSimple(control, dfItem.value());    

}
public void dialogPostRun(DialogRunbase _dialog)

{

    ;

     super(_dialog);

    **_dialog.formRun().controlMethodOverload(true);** // Causes Stack Trace error

    _dialog.formRun().controlMethodOverloadObject(this);       

}

Mayby you should call super(_dialog) last in the dialogPostRun method.
Here is an example code for overriding the modified method. Maybe lookup has the same requirements:
public void dialogPostRun(DialogRunbase _dialog)
{
// Must be overriden to enable overriding modified method
;
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);

    super(_dialog);
}
And for the custom method:
boolean Fld2_1_modified()
{
    FormStringControl c = dialog.formrun().controlCallingMethod();
    boolean ret;
    ;

    ret = c.modified(); // Super() Call the FormControl ->modified

    dlgCustomField.value(MyClass::someMethod(dlgCustomField.value())); // example

    return ret;
}
public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
    DialogRunBase   dialog;
    ;

    dialog = super(_dialog, true);

    dialog.caption('@RID2885');

    dfItem = dialog.addField(typeid(ItemId));
    dfInventLoc = dialog.addField(typeid(InventLocationId));
    dfReplaceCost = dialog.addField(typeid(PdsCost));
    dfItemConfig = dialog.addField(typeid(ConfigId));
    dfColorId = dialog.addField(typeid(InventColorId), '@RID101');

    return dialog;
}
Here's the call to the lookup():
void Fld_7_lookup()
{
    Formrun fr = this.dialogModify().parmDialog();
    Object control = fr.controlCallingMethod();
    ;

    ConfigTable::lookupConfigIdSimple(control, dfItem.value());
}
And this is where it keeps getting the Stack Trace error:
public void dialogPostRun(DialogRunbase _dialog)
{
    ;
     super(_dialog);
    **_dialog.formRun().controlMethodOverload(true);** // Causes Stack Trace error
    _dialog.formRun().controlMethodOverloadObject(this);   
}
Mayby you should call super(_dialog) last in the dialogPostRun method.

Here is an example code for overriding the modified method. Maybe lookup has the same requirements:
public void dialogPostRun(DialogRunbase _dialog)
{
// Must be overriden to enable overriding modified method
;
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);

    super(_dialog);
}
And for the custom method:
boolean Fld2_1_modified()
{
    FormStringControl c = dialog.formrun().controlCallingMethod();
    boolean ret;
    ;

    ret = c.modified(); // Super() Call the FormControl ->modified

    dlgCustomField.value(MyClass::someMethod(dlgCustomField.value())); // example

    return ret;
}
public void dialogPostRun(DialogRunbase _dialog)
{
    super(_dialog);

    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

Note, that in the code above the RunBase class itself is used as event handler (by passing this to the controlMethodOverloadObject() method), but it is possible to create a separate class for handling events.

Afterwards event handlers can be created as method with specific name: _. Control name can be found in the dialog user setup. For example, the following method will handle modify event of the first field control on the dialog:
public void fld1_1_modified()
{
    Object control;

    control = dialog.formRun().controlCallingMethod();

    if(control.modified())
    {
        info(“Modified triggered!”);
    }

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.

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 ...