Wednesday, 20 March 2013

Passing Args from Form to Class in Dynamics Ax 2012

In this post, i will demonstrate on how to pass Args from Form to Class in Dynamics Ax.


This post will helpful for those who are keen to learn about Args which is very much fruitful concept in Dynamics Ax.

The Scenario is when I select multiple grids in Form , those records will be passed to Class and once you received those records in Class and you can use it as per your Requirement.

Firstly, make one form from which you will pass the arguments and drag your table to the datasource, then drag the fields to the grid of design node, also drag one button adn override the clicked method.

write the following code in clicked method.
void clicked()
{
int recordsCount;
SampleTbl _SampleTbl;
container con;
Args args;
str multiSelectString;
;

args = new Args();
recordsCount = SampleTbl_ds.recordsMarked().lastIndex(); // gets the total records selected
_SampleTbl = SampleTbl_ds.getFirst(1);

while (_SampleTbl)
{
// storing recid of selected field in container
con = conIns(con,1,_SampleTbl.RecId);

// converting container to string with comma separated
multiSelectString = con2Str(con,',');

_SampleTbl = SampleTbl_ds.getNext(); // moves to next record
}
// passing string
args.parm(multiSelectString);
// calling menu item
new MenuFunction(identifierstr(SampleTest), MenuItemType::Action).run(args);


}

first
make one class and write the following code in main method of it.
public static void main(Args args)
{
SampleTbl _SampleTbl;
container con;
int i;
str multipleRecords;
;
multipleRecords = args.parm();
info(strFmt('%1',multipleRecords));
// i am just here an infolog of recids but you can do as per requirement once you got multiple records
}


thanks and your feedback will be appreciated

Passing Multiple Records from one form to another through Args in Dynamics Ax 2012


In my last post, i posted on how to pass Record from one Form to another Form. Now i will pass multiple Record from one Form to another through Args.


The Scenario is when I select multiple grids in Form A, those records will be passed to FormB and there FormB will received the all those records and filter it and will show.

Step 1: Make one SampleTable which has three fields named (SIno, name, AddressCity).
Step 2: Make FormA with datasource as SampleTable and drag the datasource fields into the design Grid.
Step 3: Drag one button and override the click method and write the following code.
step 4: Make one Display menuitem of FormB.


void clicked()
{

int recordsCount;
SampleTable _sampleTable;
container con;
Args args;
str multiSelectString;
;


args = new Args();
recordsCount = SampleTable_ds.recordsMarked().lastIndex(); // gets the total records selected
_sampleTable = SampleTable_ds.getFirst(1);

while (_sampleTable)
{
// storing recid of selected field in container
con = conIns(con,1,_sampleTable.RecId);

// converting container to string with comma separated
multiSelectString = con2Str(con,',');

_sampleTable = SampleTable_ds.getNext(); // moves to next record
}
// passing string
args.parm(multiSelectString);
// calling menu item
new MenuFunction(menuitemDisplayStr(FormBMenuItem), MenuItemType::Display).run(args);
}


first

step 5: Make FormB with datasource as same table for which you take for Form A i.e., SampleTable and drag the fields in to the
Grid of design part.
step 7: write the following code in to the init method of FormB.


public void init()
{
container con;
int i;
str multipleRecords;
super();
// getting string value from caller
multipleRecords = element.args().parm();

// string to container
con = str2con(multipleRecords,",");

// for sorting
for(i = 1;i<= conLen(con) ;i++)
{
SampleTbl_ds.query().dataSourceTable(Tablenum(SampleTbl)).addRange(fieldNum(SampleTbl,RecId)).value(SysQuery::value(conPeek(con,i)));
}

}


thanks and your feedback will be appreciated.

Tuesday, 19 March 2013

Passing Args from one Form to another Form in dynamics Ax 2012

Args concept in dynamics ax is awesome. one can easily pass arguments from one Form to another Form with very less effort. Here, i am going to demonstrate how to pass Arguments from Form to Form. The Scenario is when I select one grid in Form A, that record will be passed to Form B and there Form B will received the whole record and filter it and will show.

Step 1: Make one SampleTable which has three fields named (SIno, name, AddressCity).
Step 2: Make FormA with datasource as SampleTable and drag the datasource fields into the design Grid.
Step 3: Drag one button and override the click method and write the following code.

void clicked()
{
Args args;
FormRun formRun;
;
super();
args = new args(formstr(FormB)); // sending Args(record) to FormB
args.record(SampleTable);
formrun = classfactory.formrunclass(args);
formrun.init();
formrun.run();
formrun.wait();
formrun.detach();

}



first

step 4: Make FormB with datasource as same table for which you take for Form A i.e., SampleTable and drag the fields in to the
Grid of design part.

step 5: write the following code in to the init method of FormB.

public void init()
{
SampleTable _sampleTable;
super();
_sampleTable = element.args().record();
SampleTable_ds.query().dataSourceTable(Tablenum(SampleTable)).addRange(fieldNum(SampleTbl,RecId)).
value(SysQuery::value(_sampleTable.Recid));
}

Note: You can pass only one Record with this Code, if you want to pass multiple grids,i will cover in next post.


thanks and your feedback will be appreciated.