March 01, 2013

Add multiple range and multiple table lookup

Add multiple range and multiple table lookup





public void lookup()
{
SysTableLookup tableLookup;
QueryBuildRange rangeTransDate;
QueryBuildRange vlgCode,ItemId,DistCode,talCode;
QueryBuildRange CropId;
QueryRun queryRun;
QueryBuildDataSource qbds,qbds1,qbr,qbr1,qbr2;
Query q = new Query();
Query q1 = new Query();
QueryBuildLink QueryBuildLink1,QueryBuildLink2;
_TmpLookup _TmpLookup1;
InventTable InventTable_1;
boolean flg;
;
tableLookup = SysTableLookup::newParameters(tableNum(_TableDetails),this);
qbr = q.addDataSource(tableNum(_TableDetails));
qbr2=qbr.addDataSource(tablenum(_Inspection1));
qbr2.joinMode(Joinmode::NoExistsJoin);
QueryBuildLink2 = qbr2.addLink(fieldnum(_TableDetails, _TableNo),fieldnum(_Inspection1,TableNo));
// qbr2.addRange(fieldnum(_TableDetails,_TableNo)).value(queryNotValue(SysQuery::valueEmptyString()));
qbr2.relations(true);
if(tmpfilter.DistrictCode != "" )
{
qbr.addRange(fieldnum(_TableDetails,_DistrictCd)).value(queryValue(tmpfilter.DistrictCode));
}
if(tmpfilter.talCode != "" )
{
qbr.addRange(fieldnum(_TableDetails,_talCd)).value(queryValue(tmpfilter.talCode));
}
if( tmpfilter.vlgCode != "")
{
qbr.addRange(fieldnum(_TableDetails,_vlgCd)).value(queryValue(tmpfilter.vlgCode));
}
if(tmpfilter.ItemId != "")
{
qbr.addRange(fieldnum(_TableDetails,ItemId)).value(queryValue(tmpfilter.ItemId));
}
// qbr2.addRange(fieldnum(_TableDetails,_TableNo)).value(queryValue(''));
//ss
//ss
// qbr.addRange(fieldnum(_TableDetails,_Area)).value(queryNotValue(0));
//ss
qbr1 = qbr.addDataSource(tablenum(_Table));
qbr1.joinMode(Joinmode::InnerJoin);
QueryBuildLink2 = qbr1.addLink(fieldnum(_TableDetails, RegId),fieldnum(_Table,RegId));
qbr1.relations(true);
if(enum2str(tmpfilter.Season) != "")
{
qbr1.addRange(fieldnum(_Table,_SeasonId)).value(queryValue(tmpfilter.Season));
}
if(tmpfilter.CustAccount != "")
{
qbr1.addRange(fieldnum(_Table,CustAccount)).value(queryValue(tmpfilter.CustAccount));
}
// qbr2.addRange(fieldnum(_TableDetails,_TableNo)).value(queryNotValue(""));
//ss
// qbr2.addRange(fieldnum(_TableDetails,_TableNo)).value(queryValue('090000004'));
//info(_Inspection1.TableNo);
//ss
tableLookup.parmQuery(q);
tableLookup.addLookupfield(fieldNum(_TableDetails,_TableNo));
tableLookup.addLookupfield(fieldNum(_TableDetails, ItemId));
tableLookup.addLookupfield(fieldNum(_TableDetails, ItemName));
tableLookup.setLabel("Name");
tableLookup.performFormLookup();
}
-Harry

February 28, 2013

Dynamics AX – Passing parameters between object – What is args??

Hi Friends,

ARGS is your friend in the world of AX (me also :) ). It allows you to pass records, the calling locations (form, report, query etc) , ENUMS and the list goes on!  
Simple declaration of args

Args  args = new Args();

Now lets try passing args an record.

select firstonly custTable where custTable.AccountNum == ‘XXXX’
if(custTable)
{
args.record(custTable);
}

Now lets view a snippet of code that passes in a record and runs a report using the record passed in. 
I- Create an instance of the report run class.
Create a new Args instance to hold all of this information. 
Pass the name of the report.
Instantiate the report run object and call the init and and run methods of the report.

II- Next override the init method of the report and put a condition that checks to see if a record was passed to the report from the args object. If so do not allow the user to be interactive with the report and sent the report straight to the screen.

III- Set a report variable eHeader to the record that was passed to the report. If there is no calling record to the report meaning the report is being launched from a menu or elsewhere besides a place with a calling record then allow interaction of the report query for the users to select the range criteria they want to use.

IV- Then override the fetch method and keep the super in place to allow the standard query to run however before the super use a condition to determine if a record has been passed into the report. If so then set a query of a key field to the a field from the record passed in.

V- You can use args to do the same with forms as well
You can pass in objects such as maps to run reports I have done this as well and I find it very helpful and useful

void printPickList(wfsEMPickListHeader  wfsEMPickListHeader)
{
    Args                    args = new args();
    ReportRun               reportRun;
    ;

    args.name(reportStr(wfsEMExportPickList));
    args.caller(this);
    args.record(wfsEMPickListHeader);

    reportRun = classfactory.reportRunClass(args);
    reportRun.init();

    reportRun.run();
}

public void init()
{
    super();
    if(element.args().record())
    {
        this.report().interactive(false);
        this.query().interactive(false);
        this.printJobSettings().preferredTarget(PrintMedium::Screen);
        eHeader = element.args().record();

    }
    else
    {
        this.report().interactive(true);
        this.query().interactive(true);
    }
}

public boolean fetch()
{
    boolean ret;
    if(element.args().record())
    {
        element.query().dataSourceTable(tablenum(wfsEMPickListHeader)).
       addRange(fieldnum(wfsEMPickListHeader,PickListId)).value(eHeader.PickListId);
    }
    ret = super();

    return ret;
}

void wfsRMRunManualTruckLoadIdForm()
{
    wfsWhseUser    wfsWhseUser;
    FormRun        formRun;
    Args           args = new Args();
    boolean        ret = false;
    ;
    args.record(this);
    formRun = new MenuFunction(menuitemdisplaystr(wfsManualTruckLoadSelection),
    MenuItemType::Display).create(args);
    formRun.run();
    formRun.wait();
}

-Harry