Tuesday, 24 December 2013

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

static void main(Args _args)
{
    Onhandwithdates   onhandwithdate;
    ;
    onhandwithdate    = new Onhandwithdates();
    if(onhandwithdate.prompt())
    {
        onhandwithdate.run();
    }
}

public Object dialog()
{

    ;
    dialog = super();

    dfitemid     =  dialog.addField(typeid(Itemid),'Itemid');
    dfitemid.fieldControl().mandatory(true);
    // dfitemid.lookupButton(FormLookupButton::Always);
    //dates
    dffromdate   =  dialog.addField(typeid(Transdate),'From date');
    dftodate     =  dialog.addField(typeid(Transdate),'To date');

    //Dimensions
    dfg = dialog.addGroup("Inventory Dimensions");

    dfsizeid  =  dialog.addField(typeid(Itemvalue),'Size');
    dfsizeid.lookupButton(FormLookupButton::Always);

    dfssiteid  =  dialog.addField(typeid(InventSiteId),'Site');
    dfwarehouse  =  dialog.addField(typeid(InventLocationId),'Warehouse');
    dflocationid  =  dialog.addField(typeid(wMSLocationId),'Location');
    return dialog;
}

public boolean getFromDialog()
{
    boolean ret1;
    ret1 = super();

    itemidloc  =   dfitemid.value();
    if( dfitemid.value() == '')
    {
       Throw error('Please fill itemid ');
    }
    fromdate   =   dffromdate.value();
    if((!fromdate) )
    {
        Throw error("Please fill the from date");
    }
    todate     =   dftodate.value();
    if((!todate) )
    {
        Throw error("Please fill the to date");
    }
     if(fromdate > todate || todate > today() )
    {
        Throw error("Please check the fromdate and todate");
    }

    sizeid     =   dfsizeid.value();
    locationid     =   dflocationid.value();
    siteid     =   dfssiteid.value();
    warehouse     =   dfwarehouse.value();
    return ret1;
}

public ClassDescription caption()
{
    ClassDescription retloc;
    retloc = 'Onhand Quantity between dates';
    return retloc;
}

public void dialogPostRun(DialogRunbase _dialog)
{
    ;
    Super(_dialog);
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);
}

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
;
    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }

    return true;
}

void Fld4_1_lookup()
{
    FormStringControl control = dialog.formRun().controlCallingMethod();
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(Inventsize), control);
    Query                   query = new Query();
    ;
    sysTableLookup.addLookupField(fieldNum(Inventsize, itemid));
    sysTableLookup.addLookupField(fieldNum(Inventsize, InventSizeId));
    if(dfitemid.value())
    {
        query.addDataSource(tableNum(Inventsize)).addRange(fieldNum(Inventsize, itemid)).value(dfitemid.value());
    }
    //You can add the ranges for filtering
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

}
.............................................................................completed-----------------------------------------------------------

class SamSelectiveLookup extends RunBase
{
    FormStringControl   custGroupCtrl, customerCtrl;
}
void Customer_lookup()
{
    Query                   query          = new Query();
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(custTable), customerCtrl);
    ;

    sysTableLookup.addLookupField(fieldNum(custTable, accountNum));
    sysTableLookup.addLookupField(fieldNum(custTable, name));

    query.addDataSource(tableNum(custTable)).addRange(fieldNum(CustTable, CustGroup)).value(custGroupCtrl.text());
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
protected Object dialog(Dialog dialog, boolean forceOnClient)
{
    DialogRunBase ret;

    ret = super(dialog, forceOnClient);

    custGroupCtrl = ret.formBuildDesign().addControl(FormControlType::String, 'CustGroup');
    custGroupCtrl.extendedDataType(103);

    customerCtrl = ret.formBuildDesign().addControl(FormControlType::String, 'Customer');
    customerCtrl.extendedDataType(99);

    return ret;
}

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

    dialog.dialogForm().formRun().controlMethodOverload(true);
    dialog.dialogForm().formRun().controlMethodOverloadObject(this);

    custGroupCtrl = dialog.dialogForm().formRun().design().controlName('CustGroup');
    customerCtrl = dialog.dialogForm().formRun().design().controlName('Customer');
}

public container pack()
{
    return conNull();
}

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

static void main(Args _args)
{
    SamSelectiveLookup test1 = new SamSelectiveLookup();
    ;

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

public void run()
{
    try
    {
        ttsbegin;


        ttscommit;
    }
    catch (exception::DeadLock)
    {
        retry;
    }

}
-------------------------------------------------------------------------
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!”);
    }

No comments:

Post a Comment