23 November 2010

Run time Lookup with range

Form lookup with reange:
--
1.
public void lookup(FormControl _formControl, str _filterStr)
{
Query query = new Query();
SysTableLookup sysTableLookup;
QueryBuildDataSource queryBuildDataSource;
;

sysTableLookup = SysTableLookup::newParameters(tablenum(AddressCityTable_BR), _formControl);
sysTableLookup.addLookupfield(fieldnum(AddressCityTable_BR, City), true);

sysTableLookup.addLookupfield(fieldnum(AddressCityTable_BR, StateId));
sysTableLookup.addLookupfield(fieldnum(AddressCityTable_BR, CountryId));

queryBuildDataSource = query.addDataSource(tablenum(AddressCityTable_BR));

queryBuildDataSource.addRange(fieldnum(AddressCityTable_BR, StateId)).value(queryValue(zipCode.State));

queryBuildDataSource.addRange(fieldnum(AddressCityTable_BR, CountryId)).value(queryValue(zipCode.CountryRegionId));

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();
}

18 November 2010

AX Environment/Company Information on Form

AX Environment Information on UI.
--
during implementations where there are multiple environments it becomes difficult to identify which environment a form belongs to especially when there are multiple forms open form different environments (Live, Test, Prod, Training etc). I made a very simple tweak which highlights which environment a form belongs to.

click here to download the xpo

The XPO is attached below. This XPO is for AX 2009 SP1 and the SysSetupFormRun class was modified.

Hyperlink on a form

Theres a standard method \Classes\Info\urlLookup that can be used to open URLs. So you can format an URL and then just call
infolog.urlLookup( urlStr );
The call can be placed in a clicked() method of a button or somewehere else.

17 November 2010

How to change form color of Microsoft Dynamics AX 2009

In the class SysSetUpFormRun class add a following code in run method

public void run()
{
super();
this.design().colorScheme(FormColorScheme::RGB);
this.design().backgroundColor(WinAPI::RGB2int(255,0,0));
}
--
Based Upon the company we can change the color of ax
switch(curext())
{
case "CEU":
this.design().backgroundColor(red);
break;

case "DMO":
this.design().backgroundColor(yellow);
break;

default:
break;
}
--

IN AX 2012 Class: sysSetupFormRun->init()


public void init()
{
super();

//start
this.design().colorScheme(FormColorScheme::RGB);
this.design().backgroundColor(WinAPI::RGB2int(120,120,120));
this.setStatusBarBackgroundColor(255,0,200,255);// form status bar color
// end
if (this.isWorkflowEnabled())
{
workflowControls = SysWorkflowFormControls::construct(this);
workflowControls.initControls();
}
}

16 November 2010

caller - calling form with button click and caller only for a form only

---
Display->formB-Properties->RunOn: Calledform// this allow for formA.
---
Form A->button clicked()
--
void clicked()
{
Args _args;
FormRun _formRun;
EmplId _emplid;
;

super();

_emplid = EmplTable.EmplId;
_args = new Args();
_args.name(formstr(FormB));
_args.caller(this); //this refer current object form
_args.parm(_emplid);
_args.record(EmplTable);

_formRun = ClassFactory.formRunClass(_args);
_formRun.init();
_formRun.run();
_formRun.wait();

}
--
FormB->DS->init()
--
public void init()
{

EmplId _emplId;
Query query;
QueryBuildRange querybuildrangeproj;

;

super();

Switch(element.args().dataset())

{
case tablenum(EmplTable):
_emplId = element.args().parm();

query = new Query();
querybuildrangeproj = query.addDataSource(tablenum(EmplTable)).addRange(fieldnum(EmplTable, EmplId));
querybuildrangeproj.value(_emplId);// adding range value from form A
EmplTable_ds.query(query);
break;
}

}
--
Display->formB-Properties->RunOn: Calledform// this allow for formA.
----

Report Query using for To get record in fetch

------------
//Suud is Table(DS)
//qr is object for QueryRun class
------------
public boolean fetch()
{
boolean ret;
QueryRun qr;
;
qr = new QueryRun(this.query());//
// following statement is executes depends on count of records in table

while(qr.next())
{
Stud = qr.get(tablenum(Stud));// getting table num

while select Stud
{
this.send(Stud);
}
}
//ret = super();

return true;
}
-------

Report avoid null records

-------------
1
-------------

public boolean fetch()
{
boolean ret;

//ret = super();
while select Stud where Stud.Address != ''
{
this.send(Stud);
}

return true;

}
--------------
2
--------------
Report->ds->ranges->field->properties->value: !=""

09 November 2010

Validate The salesLine unit price should not less than the item cost price

SalesTable(form)->DS->SalesLine->salePrice(Field)->Validate()

public boolean validate()
{
boolean ret;

ret = super();
ret = element.validate_price();

return ret;
}
--
SalesTable(form)->Methods->

public boolean validate_price()
{
boolean ret = true;
InventTableModule inventTableModule;

;
//in this line we are using our own find method, or we can use select query.
//inventTableModule = InventTableModule::find_price(SalesLine.ItemId);
select firstonly inventTableModule where inventTableModule.ItemId == SalesLine.ItemId;

if(inventTableModule.Price > SalesLine.SalesPrice)
{
ret = false;
info("the cost price is grater then the sales price ");
}

return ret;
}

08 November 2010

Get the selected record in form

1.
void clicked()
{
common common;
salesTable salesTableRef;
;
// using DataSource cursor() methos will get the cursor selected record
common = element.dataSource().cursor();

switch (common.TableId)
{
case tableNum(salesTable) :
{
salesTableRef = common;

info(salesTableRef.SalesId);
break;
}
}



super();
}
----------
2.
In Datasource->Active()
We can get using the DataSource name like
info(SalesTable.SalesId)
----------
3.
We can use that DataSource Name like SalesTable//this will get the selected record

info(SalesTable.SalesId)

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...