Friday, 23 January 2015

Add Multiple table lookup in Ax 2012


1. Firstly create a View.
AOT>DataDictionary>View>Create View
2. Drag n drop Multiple tables
AOT>DataDictionary>View>Create View > sample View > dataSource> Sample Table1 > DataSource > Sample Table2
3. Drag Fileds from Both Table in Field Node.
AOT > Data Dictionary > View > sample View > Field Node > Drang n drop fileds
4. now save it.
5. Create Form.
6. In design node, create String Edit Control.
7. Write below code in lookup method of that control.
Public Void lookup()
{
Query query = new Query();
Systablelookup systablelookup;
QueryBuildDataSource Qbds;
systablelookup = Systablelookup::newParameters(tablenum(sampleView),Form_Control_name);
Qbds= query.addDataSource(tablenum(sampleView));
systablelookup.addLookupField(fieldNum(sampleView, field1));
systablelookup.addLookupField(fieldNum(sampleView, field2));
systablelookup.addLookupField(fieldNum(sampleView, field3));
systablelookup.parmquery(query);
systablelookup.performFormLookup();
}

Open a report with selected record in ax 2009


Write the below code on click method of button from where you want to open report.
void clicked()
{
Args args;
ReportRun reportRun;
;
args = new Args();
args.name(Reportstr(S3WorkOrderReportMain));
args.parm(salesLine.SalesId);
args.record(salesLine);
args.parmObject( args );
reportRun = classfactory.reportRunClass(args);
reportRun.init();
reportRun.run();
}
and on report init() method wriite the below code.
public void init()
{
if( element.args())
{
SalesLine.SalesId = element.args().parm();
salesLine = element.args().record();
this.query().dataSourceNo(1).addRange(fieldnum(SalesLine,SalesId)).value(SalesLine.SalesId);
}
super();
}
set interaction property for report and query –    NO

How to add date range filter on Morphx Report in Ax 2009/12


Classdeclaration:
public class ReportRun extends ObjectRun
{
DialogField salesstatus;
DialogFIeld fromDate,toDate;
SalesTable _salesTable;
TransDate _fromDate, _toDate;
}
public Object dialog(Object _dialog)
{
Dialog dialog = _dialog ;
;
// dialog = super();
// Set a title for dialog
dialog.caption( ‘Simple Dialog’);
// Add a new field to Dialog
fromDate = dialog.addField(extendedTypeStr(TransDate), ‘From Date’ );
toDate = dialog.addField(extendedTypeStr(TransDate), ‘To Date’ );
return dialog;
————————————–
public boolean getFromDialog()
{
// Retrieve values from Dialog
_fromdate = fromdate.value();
_toDate = toDate.value();
return true;
}
————————————–
public container pack()
{
return connull();
}
————————————–
public boolean unpack(container packedClass)
{
Version version = RunBase::getVersion(packedClass);
return true;
}
———————————————
public boolean fetch()
{
boolean ret = true;
// ret = super();
while select _salesTable
where _salesTable.DeliveryDate >= _fromDate
&& _salesTable.DeliveryDate <= _toDate
element.send(_salesTable);
return ret;
}
——————————————————–

Add Filter on Display Method in Ax


Step 1:
Go to the form design right click on particular control properties Auto Declaration No to Yes.

 
Step 2:
Override the context() method on the display method .
 
public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem(‘Filter By Field’);
    int b = menu.insertItem(‘Filter By Selection’);
    int c = menu.insertItem(‘Remove Filter’);
    ;
q   = ItemControl_ds.query();
qb1 = q.dataSourceTable(tablenum(ItemControl));
qb1 = qb1.addDataSource(TableNum(SalesTable));
qb1.addLink(FieldNum(ItemControl,PO),FieldNum(SalesTable,PurchOrderFormNum));
selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1: //Filter by field
            break;
    case a:
            ag = new args(‘SysformSearch’);
            fr = new formrun(ag);
            fr.run();
            fr.wait();
//Reading User entered value for filter process
            strtext = fr.design().controlName(‘FindEdit’).valueStr();
            if(strtext)
            {
//Creating a query for filter
                qb1.addRange(FieldNum(SalesTable,SearchName)).value(strtext);
                ItemControl_ds.query(Q);
                ItemControl_ds.executeQuery();
            }
            break;
    case b:                                      // Filter By Selection
            qb1.addRange(FieldNum(SalesTable,SearchName)).value(ProjName.valueStr());
            ItemControl_ds.query(Q);
            ItemControl_ds.executeQuery();
            break;
    case c :                                      // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(ItemControl));
            qb1.clearLinks();
            qb1.clearRanges();
            ItemControl_ds.query(Q);
            ItemControl_ds.removeFilter();
            break;
    Default:
            break;
    }
}
After adding the above code we are getting menus like