How to convert amount in words in Ax 2012

static void amount2words(Args _args)
{
real amount = 1011.05;
int numOfPennies = frac(amount)*100 mod 100;
int test = real2int(round(amount,0));
int paise;
int numOfTenths;
str 20 ones[19], tenths[9], hundreds, thousands, lakhs, crores, millions, billions;
str 40 textpaise;
int tmpnumofpennies;
int temp;
str 200 returntxt;

int checkPower(int _test, int _power)
{
int numOfPower;

if (_test >= _power)
{
numOfPower = _test DIV _power;
if (numOfPower >= 100)
{
temp = numOfPower DIV 100;
returntxt = returntxt + ‘ ‘ + ones[temp] + ‘ ‘ + hundreds;
numOfPower = numOfPower MOD 100;
}
if (numOfPower >= 20)
{
temp = numOfPower DIV 10;
returntxt = returntxt + ‘ ‘ + tenths[temp];
numOfPower = numOfPower MOD 10;
}
if (numOfPower >= 1)
{
returntxt = returntxt + ‘ ‘ + ones[numOfPower];
numOfPower = numOfPower MOD 10;
}
switch(_power)
{
case 1000000000 :
{
returntxt = returntxt + ‘ ‘ + billions;
_test = _test MOD 1000000000;
break;
}
case 10000000 :
{
returntxt = returntxt + ‘ ‘ + crores;
_test = _test MOD 10000000;
break;
}
case 100000 :
{
returntxt = returntxt + ‘ ‘ + lakhs;
_test = _test MOD 100000;
break;
}
case 1000 :
{
returntxt = returntxt + ‘ ‘ + thousands;
_test = _test MOD 1000;
break;
}
case 100 :
{
returntxt = returntxt + ‘ ‘ + hundreds;
_test = _test MOD 100;
break;
}
}
}
return _test;
}

ones[1] = “@SYS26620”;
ones[2] = “@SYS26621”;
ones[3] = “@SYS26622”;
ones[4] = “@SYS26626”;
ones[5] = “@SYS26627”;
ones[6] = “@SYS26628”;
ones[7] = “@SYS26629”;
ones[8] = “@SYS26630”;
ones[9] = “@SYS26631”;
ones[10] = “@SYS26632”;
ones[11] = “@SYS26633”;
ones[12] = “@SYS26634”;
ones[13] = “@SYS26635”;
ones[14] = “@SYS26636”;
ones[15] = “@SYS26637”;
ones[16] = “@SYS26638”;
ones[17] = “@SYS26639”;
ones[18] = “@SYS26640”;
ones[19] = “@SYS26641”;

tenths[1] = ‘Not used’;
tenths[2] = “@SYS26643”;
tenths[3] = “@SYS26644”;
tenths[4] = “@SYS26645”;
tenths[5] = “@SYS26646”;
tenths[6] = “@SYS26647”;
tenths[7] = “@SYS26648”;
tenths[8] = “@SYS26649”;
tenths[9] = “@SYS26650”;

hundreds = “@SYS26651”;
thousands = “@SYS26652”;
lakhs = “Lakh”;
crores = “Crore”;
millions = “@SYS26653”;
billions = “@SYS26654”;
test = checkPower(test, 1000000000);
test = checkPower(test, 10000000);
test = checkPower(test, 100000);
test = checkPower(test, 1000);
test = checkPower(test, 100);

if (test >= 20)
{
numOfTenths = test DIV 10;
returntxt = returntxt + ‘ ‘ + tenths[numofTenths];
numOfTenths = numOfTenths MOD 10;
test = test MOD 10;
}
if (test >= 1)
{
numOfTenths = test;
returntxt = returntxt + ‘ ‘ + ones[numOfTenths];
}
if (numOfPennies)
{
returntxt = returntxt + ‘ ‘ + “@SYS5534” + “\n\n”;
}
paise=numofPennies;
if(paise)
{
if(paise >=20)
{
numofTenths= paise DIV 10;
returntxt=returntxt + ‘ ‘+tenths[numofTenths];
numofTenths = numofTenths MOD 10;
paise=paise MOD 10;
}
if(paise >=1)
{
numOfTenths=paise;
returntxt=returntxt+ ‘ ‘+ones[numOfTenths];
}
returntxt=returntxt+” Paise”;
}

info(strFmt(“%1″,returntxt + ” Only”));
}

Date Filter on Report

Hi, I am filtering report data on the basis of delivery date

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;
}

——————————————————–
}

How to add filter on display method in ax 2012

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

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

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();
}

How to export, delete, Import model in Ax 2012 R2

To export a model through axUtil command we need to login on server through Admin. then

After log in go to run and type cmd and change the directory

cd C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities

  • For Exporting “USR Model” Type

AxUtil.exe export /file:c:\TestingModel.axmodel /model:”USR Model” /config:S3_AX2012R2_Standard

To see this  Config “config:S3_AX2012R2_Standard” go to Microsoft  Dynamics ax 2012 server configuration and see the AOS instance.

  •  For deleting a Model:

axutil delete /model:Testing /config:S3_AX2012R2_Standard

  • For importing a model

axutil import /file:c:\TestingModel.axmodel /config:S3_AX2012R2_Standard

How to Open Visual Studio with a Specific Configuration ax 2012 R2

Hello,

When you get an error like  “Disconnected from the AOS”.

AOTConnectError

then your AX client and server are on different machines, you need to launch your Visual Studio instance using a shortcut from AX client machine and that shortcut should have target AOS configuration.

Now come to the solution….

You have an AX configuration file called ax_2012R2.AXC to launch the correct AOS. Get a shortcut of your Visual Studio on AX client machine right click on it. You will see the property dialog as shown below.

Capture

The action you need to perform is to add target for AOS configuration file to it. To achieve this replace the path with “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe” /AxConfig “C:\Users\pramn\Desktop\Ax2012_RND.axc”

this is the location of your .AXC file

click on apply and reopen your visual studio.

and Enjoy….

Note : take care of location of .axc file that you want to use.

Print record from table through query in ax

Here I am using a query to show all the Customer account number from CustTable.

static void Job31(Args _args)
{
Query                                          query;
QueryRun                                    qr;
CustTable                                    custtable;
AccountNum                                accountNum;
QueryBuildDataSource                qbds;
;

query = new query();
qbds = query.addDataSource(tablenum(CustTable));
qr = new QueryRun(query);

while(qr.next())
{
custtable = qr.get(tablenum(CustTable));

info(strfmt(“%1”, custtable.AccountNum));
}

}

Filter form data on form open in axapta using query and code

In this post I am filtering vendgroup data which have value tax payment.

Table Used : VendTable

Filter on : VendGroup

Value : Tax Payment

In the ClassDeclaration method of the form, define a range.

Step 1:

public class FormRun extends ObjectRun
{
QueryBuildRange qbr;

}

Step 2:

On Form Datasource override init method.

public void init()
{
super();

qbr = this.query().dataSourceName(‘VendTable’).addRange(fieldnum(vendTable,VendGroup));

}

Step 3:

On Form Datasource override ExecuteQuery method.

public void executeQuery()
{

qbr.value(queryvalue(‘Tax Payment’));
super();
}

Done…!!!!!!

The same thing you can do by query

Go to Queries node in AOT

create a query and set datasource VendTable

in range you have to set value by which you want to filter the record. like below

Capture