MyTable MyTablecopy;
MyTable MyTabletmp;
Common Common;
int row = 1;
int rowmax;
;
MyTabletmp.setTmp();
MyTabletmp.clear();
rowMax = MyTable_ds.totalNumberOfRows();
Common = MyTable_ds.getFirst();
while (row <= rowmax)
{
select firstOnly MyTablecopy where MyTablecopy.RecId == Common.RecId;
if(MyTablecopy)
{
MyTabletmp.MyTableId = int2str(row);
MyTabletmp.itemId =MyTablecopy.itemid;
MyTabletmp.insert();
}
row++;
Common = MyTable_ds.getnext();
}
Microsoft Dynamics AX 4.0 data model overview
I have great news for you, readers :)
Recently, on an internal Microsoft discussion group, I received a nice document with an overview of the data model for Dynamics AX 4.0.
After permission was received to publish this document to an external audience, I uploaded it to my personal web-site, so that all of you can download it at a convenient time.
The link is below. Enjoy!
Download AX40datamodel.doc (4.41 Mb)
UPD: A newer version of this document does not exist, so I won't be able to post it here
Recently, on an internal Microsoft discussion group, I received a nice document with an overview of the data model for Dynamics AX 4.0.
After permission was received to publish this document to an external audience, I uploaded it to my personal web-site, so that all of you can download it at a convenient time.
The link is below. Enjoy!
Download AX40datamodel.doc (4.41 Mb)
UPD: A newer version of this document does not exist, so I won't be able to post it here
- Read the complete post at http://kashperuk.blogspot.com/2008/09/microsoft-dynamics-ax-40-data-model.html
Posting wmsjournaltable
static void WMSJournalProd(Args _args)
{
WMSJournalName WMSJournalName;
WMSJournalTable WMSJournalTable;
WMSJournalTrans WMSJournalTrans;
JournalTableData JournalTableData;
journalCheckPost journalCheckPost;
int logPointerLast;
int lineBeforeCLRError;
boolean errors;
;
logPointerLast = infolog.num(0);
lineBeforeCLRError = infolog.line();
//get journal name
wmsJournalName = WMSJournalName::find("PrWE");
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
//wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = "PA389238";
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.inventDimId = InventDim::inventDimIdBlank();
wmsJournalTable.insert();
journalTableData = JournalTableData::newTable(wmsJournalTable);
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.transDate = systemdateget();
//wmsJournalTrans.inventTransRefId = "PA389238";
wmsJournalTrans.insert();
//post the journal
journalCheckPost = WMSJournalCheckPostReception::newTypeJournalTable(JournalCheckPostType::Post,wmsJournalTable);
journalCheckPost.parmAutoBlock(true); // den Wert 'vom System geblockt' auf 'TRUE', sonst Fehlermeldung
journalCheckPost.run();
errors = journalTableData.hasErrors();
if(errors)
error(infolog.text(logPointerLast+1));
}
Best regards
Michael
obewankenob wrote:
Hi,some help would be greatly appreciated on this.
30-Jan-09
Hi,
some help would be greatly appreciated on this. Again, most of the info is
related to invent journals, but I cant seem to translate this through to the
warehouse journal. I am having problems with posting the production journal.
My code is as follows:
//get journal name
wmsJournalName = WMSJournalName::find(wmsJournalNameId);
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = myprodId;
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.insert();
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.inventTransRefId = myprodId;
wmsJournalTrans.insert();
//assign pallet id
inventDim::find(wmsJournalTrans.inventDimId);
inventDim.wmsPalletId = WMSPalletIdGenerate::nextPalletId();
wmsjournalTrans.update();
//post the journal
journalCheckPost = new journalCheckPost();
journalCheckPost.initParmDefault();
journalCheckPost.parmJournalId(wmsJournalTable.journalId);
journalCheckPost.parmJournalCheckPostType(journalCheckPOstType::Post);
journalCheckPost.parmJournalTableId(wmsJournalTable.TableId);
journalCheckPost.run();
I would really appreciate some advice on this peeps.
Thanks
"obewankenobe" wrote:
Previous Posts In This Thread:
On Tuesday, January 27, 2009 8:31 AM
obewankenob wrote:
WMSjournalCheckPost
Hi,
I am trying to post a production input journal using the WMSJournalCheckPost
class. I originally hoped it would be similar in approach to the
InventJournalCheckPost class:
inventJournalCheckPOst::newPostJournal(inventJournalTable).run();
But when using the WMS version I only have wmsJournalCheckPost::main exposed.
Attempting to use main and give a new set of args returns errors saying my
arguments don't match:
wmsJournalCheckPost = wmsJournalCheckPost::main(new args());
I Have (well at least I think I have) created a new journal record and
assigned new lines to it for the production journal, it is now just a matter
of posting.
Can anyone help?
thanks.
On Tuesday, January 27, 2009 12:55 PM
obewankenob wrote:
As an update, my code is still issuing errors.
As an update, my code is still issuing errors.
Attempted to use JournalCheckPost to post the journal, but am having several
p[roblems:
1) creating lines in the journal - I have entered records in the
WMSJournalTrans table as well as use the wmsJournalCreateLines class and both
don't seem to be producing the goods.
2) Again, using JournalCheckPost, I am attempting to post the journal, but
am getting the following error: Buffer not specified for call
JournalStatic::findJournalTableId.
Any ideas?
"obewankenobe" wrote:
On Friday, January 30, 2009 7:27 AM
obewankenob wrote:
Hi,some help would be greatly appreciated on this.
Hi,
some help would be greatly appreciated on this. Again, most of the info is
related to invent journals, but I cant seem to translate this through to the
warehouse journal. I am having problems with posting the production journal.
My code is as follows:
//get journal name
wmsJournalName = WMSJournalName::find(wmsJournalNameId);
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = myprodId;
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.insert();
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.inventTransRefId = myprodId;
wmsJournalTrans.insert();
//assign pallet id
inventDim::find(wmsJournalTrans.inventDimId);
inventDim.wmsPalletId = WMSPalletIdGenerate::nextPalletId();
wmsjournalTrans.update();
//post the journal
journalCheckPost = new journalCheckPost();
journalCheckPost.initParmDefault();
journalCheckPost.parmJournalId(wmsJournalTable.journalId);
journalCheckPost.parmJournalCheckPostType(journalCheckPOstType::Post);
journalCheckPost.parmJournalTableId(wmsJournalTable.TableId);
journalCheckPost.run();
I would really appreciate some advice on this peeps.
Thanks
"obewankenobe" wrote:
On Wednesday, June 10, 2009 2:43 PM
Fines wrote:
Hello obewankenobe,We had the same situation but with an item arrival journal,
Hello obewankenobe,
We had the same situation but with an item arrival journal, using this
sample code the post is working (Dynamics AX 2009 SP1):
static void testPostItemArrivalJournal(Args args)
{
WMSJournalCheckPost _WMSJournalCheckPost;
wmsJournalTable _wmsJournalTable;
;
_WMSJournalCheckPost = new WMSJournalCheckPostReception();
_WMSJournalCheckPost.parmAutoBlock(false);
_WMSJournalCheckPost.parmShowInfoResult(true);
_WMSJournalCheckPost.parmJournalCheckPostType(journalCheckPostType::Post);
_WMSJournalCheckPost.parmJournalTableId(_wmsJournalTable.TableId);
_WMSJournalCheckPost.parmJournalId("0000121");
_WMSJournalCheckPost.run();
}
{
WMSJournalName WMSJournalName;
WMSJournalTable WMSJournalTable;
WMSJournalTrans WMSJournalTrans;
JournalTableData JournalTableData;
journalCheckPost journalCheckPost;
int logPointerLast;
int lineBeforeCLRError;
boolean errors;
;
logPointerLast = infolog.num(0);
lineBeforeCLRError = infolog.line();
//get journal name
wmsJournalName = WMSJournalName::find("PrWE");
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
//wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = "PA389238";
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.inventDimId = InventDim::inventDimIdBlank();
wmsJournalTable.insert();
journalTableData = JournalTableData::newTable(wmsJournalTable);
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.transDate = systemdateget();
//wmsJournalTrans.inventTransRefId = "PA389238";
wmsJournalTrans.insert();
//post the journal
journalCheckPost = WMSJournalCheckPostReception::newTypeJournalTable(JournalCheckPostType::Post,wmsJournalTable);
journalCheckPost.parmAutoBlock(true); // den Wert 'vom System geblockt' auf 'TRUE', sonst Fehlermeldung
journalCheckPost.run();
errors = journalTableData.hasErrors();
if(errors)
error(infolog.text(logPointerLast+1));
}
Best regards
Michael
obewankenob wrote:
Hi,some help would be greatly appreciated on this.
30-Jan-09
Hi,
some help would be greatly appreciated on this. Again, most of the info is
related to invent journals, but I cant seem to translate this through to the
warehouse journal. I am having problems with posting the production journal.
My code is as follows:
//get journal name
wmsJournalName = WMSJournalName::find(wmsJournalNameId);
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = myprodId;
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.insert();
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.inventTransRefId = myprodId;
wmsJournalTrans.insert();
//assign pallet id
inventDim::find(wmsJournalTrans.inventDimId);
inventDim.wmsPalletId = WMSPalletIdGenerate::nextPalletId();
wmsjournalTrans.update();
//post the journal
journalCheckPost = new journalCheckPost();
journalCheckPost.initParmDefault();
journalCheckPost.parmJournalId(wmsJournalTable.journalId);
journalCheckPost.parmJournalCheckPostType(journalCheckPOstType::Post);
journalCheckPost.parmJournalTableId(wmsJournalTable.TableId);
journalCheckPost.run();
I would really appreciate some advice on this peeps.
Thanks
"obewankenobe" wrote:
Previous Posts In This Thread:
On Tuesday, January 27, 2009 8:31 AM
obewankenob wrote:
WMSjournalCheckPost
Hi,
I am trying to post a production input journal using the WMSJournalCheckPost
class. I originally hoped it would be similar in approach to the
InventJournalCheckPost class:
inventJournalCheckPOst::newPostJournal(inventJournalTable).run();
But when using the WMS version I only have wmsJournalCheckPost::main exposed.
Attempting to use main and give a new set of args returns errors saying my
arguments don't match:
wmsJournalCheckPost = wmsJournalCheckPost::main(new args());
I Have (well at least I think I have) created a new journal record and
assigned new lines to it for the production journal, it is now just a matter
of posting.
Can anyone help?
thanks.
On Tuesday, January 27, 2009 12:55 PM
obewankenob wrote:
As an update, my code is still issuing errors.
As an update, my code is still issuing errors.
Attempted to use JournalCheckPost to post the journal, but am having several
p[roblems:
1) creating lines in the journal - I have entered records in the
WMSJournalTrans table as well as use the wmsJournalCreateLines class and both
don't seem to be producing the goods.
2) Again, using JournalCheckPost, I am attempting to post the journal, but
am getting the following error: Buffer not specified for call
JournalStatic::findJournalTableId.
Any ideas?
"obewankenobe" wrote:
On Friday, January 30, 2009 7:27 AM
obewankenob wrote:
Hi,some help would be greatly appreciated on this.
Hi,
some help would be greatly appreciated on this. Again, most of the info is
related to invent journals, but I cant seem to translate this through to the
warehouse journal. I am having problems with posting the production journal.
My code is as follows:
//get journal name
wmsJournalName = WMSJournalName::find(wmsJournalNameId);
//create new journal table record
wmsJournalTable.initFromWMSJournalName(wmsJournalName);
wmsJournalTable.journalType = wmsJournalType::Production;
wmsJournalTable.inventTransRefId = myprodId;
wmsJournalTable.inventTransType = inventTransType::Production;
wmsJournalTable.insert();
//create new journal line
wmsJournalTrans.initFromWMSJournalTable(wmsJournalTable);
wmsJournalTrans.inventTransRefId = myprodId;
wmsJournalTrans.insert();
//assign pallet id
inventDim::find(wmsJournalTrans.inventDimId);
inventDim.wmsPalletId = WMSPalletIdGenerate::nextPalletId();
wmsjournalTrans.update();
//post the journal
journalCheckPost = new journalCheckPost();
journalCheckPost.initParmDefault();
journalCheckPost.parmJournalId(wmsJournalTable.journalId);
journalCheckPost.parmJournalCheckPostType(journalCheckPOstType::Post);
journalCheckPost.parmJournalTableId(wmsJournalTable.TableId);
journalCheckPost.run();
I would really appreciate some advice on this peeps.
Thanks
"obewankenobe" wrote:
On Wednesday, June 10, 2009 2:43 PM
Fines wrote:
Hello obewankenobe,We had the same situation but with an item arrival journal,
Hello obewankenobe,
We had the same situation but with an item arrival journal, using this
sample code the post is working (Dynamics AX 2009 SP1):
static void testPostItemArrivalJournal(Args args)
{
WMSJournalCheckPost _WMSJournalCheckPost;
wmsJournalTable _wmsJournalTable;
;
_WMSJournalCheckPost = new WMSJournalCheckPostReception();
_WMSJournalCheckPost.parmAutoBlock(false);
_WMSJournalCheckPost.parmShowInfoResult(true);
_WMSJournalCheckPost.parmJournalCheckPostType(journalCheckPostType::Post);
_WMSJournalCheckPost.parmJournalTableId(_wmsJournalTable.TableId);
_WMSJournalCheckPost.parmJournalId("0000121");
_WMSJournalCheckPost.run();
}
Posting InventJournal from X++
The following code is extract from http://rusgon.blogspot.com/2008/02/posting-inventjournal-from-x.html
thanks about his research,
Once I was faced the problem to post InventJournal from code.
At first glance it's easy. Let's open AOT. Then we find corresponding Menu Item in \Menu Items\Action\InventJournalPost. Open class InventJournalCheckPost... And looking at main() method of this class we are coming to conclusion that this class is tightly tied to the journalForm. What's a pity!
So let's try to write own code.
At first glance it's easy. Let's open AOT. Then we find corresponding Menu Item in \Menu Items\Action\InventJournalPost. Open class InventJournalCheckPost... And looking at main() method of this class we are coming to conclusion that this class is tightly tied to the journalForm. What's a pity!
So let's try to write own code.
X++:
static void main(Args args)
{
InventJournalCheckPost journalCheckPost;
journalForm journalForm;
;
journalForm = journalForm::fromArgs(args);
journalCheckPost = InventJournalCheckPost::newFromForm(args,journalForm);
journalForm.runbaseMainStart();
if (!journalCheckPost.PROMPT())
{
if (! journalCheckPost.BatchInfo().parmBatchExecute())
journalForm.runbaseMainCancel();
return;
}
try
{
journalCheckPost.run();
journalForm.runbaseMainEnd(journalCheckPost,false);
}
catch (Exception::Error)
{
journalForm.runbaseMainEnd(journalCheckPost,true);
}
}
First of all we need to get rid of journalForm.
Let's rewrite newFromForm() method. The parameters wich passing into this method are used to achieve InventJournalTable. So we may just pass InventJournalTable into our new method.
Let's rewrite newFromForm() method. The parameters wich passing into this method are used to achieve InventJournalTable. So we may just pass InventJournalTable into our new method.
X++:
JournalCheckPost getJournalCheckPost(InventJournalTable _inventJournalTable)
{
// \Menu Items\Action\InventJournalPost
switch(inventJournalTable.journalType)
{
case InventJournalType::Movement:
case InventJournalType::LossProfit:
case InventJournalType::Transfer:
case InventJournalType::BOM:
case InventJournalType::Count:
case InventJournalType::project:
case InventJournalType::Asset:
journalCheckPost_Mov = InventJournalCheckPost
_Movement::newJournalCheckPost(
false,true, JournalCheckPostType::Post,
_inventJournalTable.tableId,
_inventJournalTable.journalId);
// journalTransData = _journalForm.JournalTransData();
// if (journalTransData)
// journalCheckPost_Mov.parmVoucher
//(journalTransData.journalTrans().voucher);
return journalCheckPost_Mov;
case InventJournalType::TagCounting:
journalCheckPost =
InventJournalCheckPost_Tag::newJournalCheckPost(
false, true, JournalCheckPostType::Post,
inventJournalTable.tableId,
_inventJournalTable.journalId);
return journalCheckPost_Tag;
}
}
Look at JournalFormTable class. It extends journalForm class.
Inside of runbaseMainStart() method we may find following line
journalTableData.updateBlock(JournalBlockLevel::None,JournalBlockLevel::System,false);
inside of runbaseMainCancel() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
and inside of runbaseMainEnd() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
That's enough. Now we may rewrite main() method:
Inside of runbaseMainStart() method we may find following line
journalTableData.updateBlock(JournalBlockLevel::None,JournalBlockLevel::System,false);
inside of runbaseMainCancel() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
and inside of runbaseMainEnd() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
That's enough. Now we may rewrite main() method:
X++:
// Posting start. According to \Classes\InventJournalCheckPost
// journalForm.runbaseMainStart();
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::None, JournalBlockLevel::System, false);
journalCheckPost = getJournalCheckPost(inventJournalTable);
if (!journalCheckPost.PROMPT())
{
if (! journalCheckPost.BatchInfo().parmBatchExecute())
{
// journalForm.runbaseMainCancel();
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false);
}
return;
}
try
{
journalCheckPost.run();
// journalForm.runbaseMainEnd(journalCheckPost,false);
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false);
}
catch (Exception::Error)
{
// journalForm.runbaseMainEnd(journalCheckPost,true);
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, true);
}
// Posting end
Finally, we are ready to write our remarkable job:
X++:
static void JobInventJournalPost(Args _args)
{
InventJournalCheckPost_Movement journalCheckPost_Mov;
InventJournalCheckPost_Tag journalCheckPost_Tag;
InventJournalCheckPost journalCheckPost;
InventJournalTable inventJournalTable;
InventJournalId inventJournalId = 'Inv002372';
JournalCheckPost getJournalCheckPost(InventJournalTable _inventJournalTable)
{
// \Menu Items\Action\InventJournalPost
switch(_inventJournalTable.journalType)
{
case InventJournalType::Movement:
case InventJournalType::LossProfit:
case InventJournalType::Transfer:
case InventJournalType::BOM:
case InventJournalType::Count:
case InventJournalType::project:
case InventJournalType::Asset:
journalCheckPost_Mov =
InventJournalCheckPost_Movement::newJournalCheckPost(
false,true, JournalCheckPostType::Post,
_inventJournalTable.tableId,
_inventJournalTable.journalId);
// journalTransData = _journalForm.JournalTransData();
// if (journalTransData)
// journalCheckPost_Mov.parmVoucher(journalTransData.journalTrans().voucher);
return journalCheckPost_Mov;
case InventJournalType::TagCounting:
journalCheckPost = InventJournalCheckPost_Tag::newJournalCheckPost(
false, true, JournalCheckPostType::Post, _inventJournalTable.tableId,
_inventJournalTable.journalId);
return journalCheckPost_Tag;
}
}
;
inventJournalTable = InventJournalTable::find(inventJournalId);
if(inventJournalTable)
{
// Posting start. According to \Classes\InventJournalCheckPost
// journalForm.runbaseMainStart();
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::None, JournalBlockLevel::System, false);
journalCheckPost = getJournalCheckPost(inventJournalTable);
if (!journalCheckPost.PROMPT())
{
if (! journalCheckPost.BatchInfo().parmBatchExecute())
{
// journalForm.runbaseMainCancel();
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false);
}
return;
}
try
{
journalCheckPost.run();
// journalForm.runbaseMainEnd(journalCheckPost,false);
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false);
}
catch (Exception::Error)
{
// journalForm.runbaseMainEnd(journalCheckPost,true);
journalTableData::updateBlockServer(
inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, true);
}
// Posting end
Invent Movement Journal Creation and Posting
static void MovementJournalImportExcel(Args _args)
{
InventJournalTrans inventJournalTrans;
InventDim inventDim;
InventJournalTable inventJournalTable;
InventJournalCheckPost journalCheckPost;
InventJournalId journalId;
journalTableData journalTabledata;
InventBatch inventBatch;
InventBatch localInventBatch;
NumberSeq numberSeq;
NumberSequenceReference numberSequenceReference;
InventSerial inventSerial;
InventSerial localinventSerial;
int j,countno=0,i,k;
real Scarp;
FilenameOpen filename;
Sysexcelapplication excelapp=sysexcelapplication::construct();
sysexcelworksheet excelworksheet;
sysexcelrange excelrange;
sysexcelcells excelcells;
// comvariant cellvalue=new comvariant();
;
// Creating Journal Header
inventJournaltable.initValue();
inventJournalTable.JournalNameId = 'ERecover';
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
inventJournalTable.JournalId = numberseq.num();
inventJournalTable.Description = InventJournalName::find(
inventJournalTable.JournalNameId).Description;
inventJournalTable.insert();
excelapp.workbooks().open('C:\\Documents and
Settings\\asrivastava\\Desktop\\ElectronicData_OnlyWstatus_10032007.xls');
excelworksheet=excelapp.worksheets().itemFromNum(1);
excelcells=excelworksheet.cells();
// Creating Unit Numbers
for(i=301;i<=5600;i++)
{
inventBatch.clear();
inventBatch.initValue();
inventBatch.itemId = excelcells.item(i,11).value().bStr();
inventBatch.inventBatchId = excelcells.item(i,1).value().bStr();
localinventBatch = InventBatch::find(inventBatch.inventBatchId,
inventBatch.itemId);
if(!localinventBatch)
{
inventBatch.OakSerialUnit = excelcells.item(i,2).value().bStr();
inventBatch.insert();
}
}
//Creating Appartment Numbers
for(k=1;k<=648;k++)
{
inventSerial.clear();
inventSerial.initValue();
inventSerial.InventSerialId = excelcells.item(k,8).value().bStr();
inventSerial.ItemId = excelcells.item(k,11).value().bStr();
localinventSerial = InventSerial::find(inventSerial.InventSerialId,
inventSerial.ItemId);
if(!localInventSerial)
{
inventSerial.ProdDate = systemDateGet();
inventSerial.insert();
}
}
// Creating Journal Lines
for(j=301;j<=5600;j++)
{
inventJournalTrans.clear();
inventJournalTrans.initValue();
inventJournalTrans.TransDate = systemDateGet();
inventJournalTrans.LedgerAccountIdOffset = "99999";
inventJournalTrans.JournalType = InventJournalType::Movement;
inventJournalTrans.JournalId = inventJournalTable.JournalId;
numberSeq = new NumberSeq();
numberSequenceReference =
InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
inventJournalTrans.Voucher = numberseq.num();
inventJournalTrans.ItemId = excelcells.item
(j,11).value().bStr();
// defaulting branch and item name
inventJournalTrans.CostAmount = InventTable::find(
inventJournalTrans.ItemId).inventTableModuleInvent().Price;
inventJournalTable = InventJournalTable::find(
inventJournalTrans.JournalId);
inventDim.InventLocationId = excelcells.item
(j,10).value().bStr();
inventDim.inventBatchId = excelcells.item
(j,1).value().bStr();
inventDim.inventSerialId = excelcells.item
(j,8).value().bStr();
inventJournalTrans.InventDimId =
inventDim::findOrCreate(inventDim).inventDimId;
inventJournalTrans.Qty = 1;
inventJournalTrans.AdjustmentNotes = "Initial Data Load";
inventJournalTrans.LineNum = j;
inventJournalTrans.insert();
}
excelapp.workbooks().item(1).saved(true);
excelapp.workbooks().close();
// Posting Journal
journalTableData = JournalTableData::newTable(inventJournalTable);
journalTableData.updateBlock
(JournalBlockLevel::InUse,JournalBlockLevel::None);
if (!infolog.num(Exception::Error))
{
infolog.clear(0);
journalCheckPost =
InventjournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post,InventJournalTable);
journalCheckPost.parmAutoBlock(true);
journalCheckPost.run();
}
}
{
InventJournalTrans inventJournalTrans;
InventDim inventDim;
InventJournalTable inventJournalTable;
InventJournalCheckPost journalCheckPost;
InventJournalId journalId;
journalTableData journalTabledata;
InventBatch inventBatch;
InventBatch localInventBatch;
NumberSeq numberSeq;
NumberSequenceReference numberSequenceReference;
InventSerial inventSerial;
InventSerial localinventSerial;
int j,countno=0,i,k;
real Scarp;
FilenameOpen filename;
Sysexcelapplication excelapp=sysexcelapplication::construct();
sysexcelworksheet excelworksheet;
sysexcelrange excelrange;
sysexcelcells excelcells;
// comvariant cellvalue=new comvariant();
;
// Creating Journal Header
inventJournaltable.initValue();
inventJournalTable.JournalNameId = 'ERecover';
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
inventJournalTable.JournalId = numberseq.num();
inventJournalTable.Description = InventJournalName::find(
inventJournalTable.JournalNameId).Description;
inventJournalTable.insert();
excelapp.workbooks().open('C:\\Documents and
Settings\\asrivastava\\Desktop\\ElectronicData_OnlyWstatus_10032007.xls');
excelworksheet=excelapp.worksheets().itemFromNum(1);
excelcells=excelworksheet.cells();
// Creating Unit Numbers
for(i=301;i<=5600;i++)
{
inventBatch.clear();
inventBatch.initValue();
inventBatch.itemId = excelcells.item(i,11).value().bStr();
inventBatch.inventBatchId = excelcells.item(i,1).value().bStr();
localinventBatch = InventBatch::find(inventBatch.inventBatchId,
inventBatch.itemId);
if(!localinventBatch)
{
inventBatch.OakSerialUnit = excelcells.item(i,2).value().bStr();
inventBatch.insert();
}
}
//Creating Appartment Numbers
for(k=1;k<=648;k++)
{
inventSerial.clear();
inventSerial.initValue();
inventSerial.InventSerialId = excelcells.item(k,8).value().bStr();
inventSerial.ItemId = excelcells.item(k,11).value().bStr();
localinventSerial = InventSerial::find(inventSerial.InventSerialId,
inventSerial.ItemId);
if(!localInventSerial)
{
inventSerial.ProdDate = systemDateGet();
inventSerial.insert();
}
}
// Creating Journal Lines
for(j=301;j<=5600;j++)
{
inventJournalTrans.clear();
inventJournalTrans.initValue();
inventJournalTrans.TransDate = systemDateGet();
inventJournalTrans.LedgerAccountIdOffset = "99999";
inventJournalTrans.JournalType = InventJournalType::Movement;
inventJournalTrans.JournalId = inventJournalTable.JournalId;
numberSeq = new NumberSeq();
numberSequenceReference =
InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
inventJournalTrans.Voucher = numberseq.num();
inventJournalTrans.ItemId = excelcells.item
(j,11).value().bStr();
// defaulting branch and item name
inventJournalTrans.CostAmount = InventTable::find(
inventJournalTrans.ItemId).inventTableModuleInvent().Price;
inventJournalTable = InventJournalTable::find(
inventJournalTrans.JournalId);
inventDim.InventLocationId = excelcells.item
(j,10).value().bStr();
inventDim.inventBatchId = excelcells.item
(j,1).value().bStr();
inventDim.inventSerialId = excelcells.item
(j,8).value().bStr();
inventJournalTrans.InventDimId =
inventDim::findOrCreate(inventDim).inventDimId;
inventJournalTrans.Qty = 1;
inventJournalTrans.AdjustmentNotes = "Initial Data Load";
inventJournalTrans.LineNum = j;
inventJournalTrans.insert();
}
excelapp.workbooks().item(1).saved(true);
excelapp.workbooks().close();
// Posting Journal
journalTableData = JournalTableData::newTable(inventJournalTable);
journalTableData.updateBlock
(JournalBlockLevel::InUse,JournalBlockLevel::None);
if (!infolog.num(Exception::Error))
{
infolog.clear(0);
journalCheckPost =
InventjournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post,InventJournalTable);
journalCheckPost.parmAutoBlock(true);
journalCheckPost.run();
}
}
How to know selected rows in a grid
Multiple grid selections
From Axaptapedia
Dealing with multiple grid selections in Axapta is much easier than it first appears.Ensure that the MultiSelect property is set to true on any relevant buttons (ie buttons that should operate on multiple rows)
Use the following code to process the rows. Note that this will work whether the user has selected only a single, or multiple rows. The getFirst method decide if you get the active row (parameter= true) or multiple rows (parameter = false).
for (buffer = table_ds.getFirst(true) ? table_ds.getFirst(true) :
table_ds.cursor(); buffer; buffer = table_ds.getnext()) { // Some processing }In the example, table_ds is used to signify the datasource and buffer should be declared as the correct table type.
For example, if you were writing this code on the SalesTable form, dealing with selected sales order header, you would use an instance of SalesTable for buffer, and SalesTable_ds as the datasource.
If the code is being run from another location, such as in a class method, then the easiest option is to pass through the current record from the form, and retrieve the datasource from that record using the datasource() method.
For example, if we have a class being called from a MenuItemButton on the form, then args().record() will contain the currently selected record. In this case, we can use the following code in main() of our class:
SalesTable salesTable; FormDataSource salesTable_ds; ; salesTable = _args.record() if (salesTable.dataSource()) salesTable_ds = salesTable.dataSource();We can then use the standard code above, with salesTable for the buffer, and salesTable_ds for the datasource.
example :
public boolean closedOk()
{
boolean ret;
str ListOfPallet;
wmspallet buffer;
ret = super();
for (buffer = wmspallet_ds.getFirst(true) ? wmspallet_ds.getFirst(true) : wmspallet_ds.cursor(); buffer; buffer = wmspallet_ds.getnext())
{
ListOfPallet += buffer.wmspalletid +",";
}
ListOfPallet = strDel(ListOfPallet,strLen(ListOfPallet),1);
return ret;
}
Passing parms between forms
Args class
From Axaptapedia
Jump to: navigation, search
The Args system class is one of the most widely used classes in Axapta. Args is an abbreviation for arguments and an Args object is used to pass information from one object (caller) to another newly created object. Contents [hide]
1 Using Args for object creation
2 Methods and Properties
2.1 caller
2.2 record
2.3 dataset
2.4 lookupField
2.5 lookupValue
2.6 parm
2.7 parmEnum
2.8 parmEnumType
2.9 parmObject
2.10 menuItemName
2.11 menuItemType
3 Examples
[edit] Using Args for object creation
The Args object can also be used to assist in object creation, in conjunction with the ClassFactory. For example, to open a CustTable form, you can use the following code:
Args args = new Args("CustTable");
FormRun formRun = ClassFactory.formRunClass(args);
;
formRun.init();
formRun.run();
formRun.wait();[edit] Methods and Properties
[edit] caller
public Object caller( [Object _value] )
this method gets or sets the calling object. When creating an args object directly through code, the caller will not be automatically set, so you should set it yourself.
[edit] record
public Common record( [Common _value] )
this method gets or sets a table buffer (record) attached to the Args. A buffer of any table can be attached to an Args object using this method. Be aware when retrieving the buffer that there will be no compile-time check of table id. You should use the dataset method below to check the contents of the buffer.
If the caller and callee are on different tiers, then the applications will automatically copy the buffer to the target tier.
[edit] dataset
public tableId dataset()
this method gets the table Id of a table buffer (record) attached to the Args.
To safely retrieve an attached record from an Args object, use code similar to that shown below. This checks to ensure that there is an attached record, and that it is in fact a SalesTable record, before trying to assign it to the salesTable variable.
if (args.record() && args.dataset() == tableNum(SalesTable))
salesTable = args.record();
[edit] lookupField
public fieldId lookupField( [fieldId _value] )
see lookupValue
[edit] lookupValue
public str lookupValue( [str _value] )
lookupField and lookupValue are used together. When they are filled with a field Id and value, it indicates that a form opened using the current Args object will automatically select a record based on that criteria.
For example, the following code assumes that a customer with the account code "1000" exists. It will open the CustTable form with customer '1000' selected, but with the other customers still shown. This is the same result visually as is achieved using the Go to Main Table function in Axapta 3.0 and higher.
Args args = new Args("CustTable");
FormRun formRun;
;
// Look up customer 1000 when the form opens
args.lookupField(fieldNum(CustTable, AccountNum));
args.lookupValue("1000");
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();Note that this lookup is extremely fast, and should be used in preference to calling .findValue or .findRecord once the form has opened.
[edit] parm
public str parm( [str _value] )
parm is used to pass a string variable to the called object
[edit] parmEnum
public anytype parmEnum( [int _value] )
see parmEnumType
[edit] parmEnumType
public int parmEnumType( [int _value] )
parmEnum and parmEnumType are used together to pass a Base Enum value through to the called object. An example is shown below.
args.parmEnumType(EnumNum(AddressType));
args.parmEnum(AddressType::Delivery);
[edit] parmObject
public Object parmObject( [Object _value] )
parmObject is used to pass a reference to any object to the called object. Be aware of client-server issues if the caller and callee are on different tiers.
[edit] menuItemName
public final str menuItemName( [str _value] )
[edit] menuItemType
public final MenuItemType menuItemType( [MenuItemType _value] )
[edit] Examples
Passing values between forms
From Axaptapedia
Jump to: navigation, search
For passing parameters from one form to another a special class Args is usually used.
Example:
The code of button click event of FormA which calls FormB and passes some parameters to that form.
void clicked()
{
// Args class is usually used in Axapta for passing parameters between forms
Args args;
FormRun formRun;
// Our custom made class for passing complex set of parameters
FormBParams formBParams = new FormBParams();
Array items = new Array( Types::String );
int i;
;
args = new args();
// Our values which we want to pass to FormB
// If we want pass just simple string we can use 'parm' method of 'Args' class
args.parm( strValue.text() );
// We also can pass enum value to FormB
args.parmEnum( NoYesEnumValue.selection() );
args.parmEnumType( EnumNum( NoYes ) );
// and also can pass a cursor pointing to some record (in our case it is EmplTable )
args.record( EmplTable );
// If we want pass more complex set of parameters we can develop our own class
// just for passing our parameters.
formBParams.parmSomeDate( someDate.dateValue() );
formBParams.parmSomeTime( someTime.value() );
for( i=0; i<ListBox.items(); i++ )
{
items.value( i+1, ListBox.getText( i ) );
}
formBParams.parmItems( items );
// Pass our object to FormB
args.parmObject( formBParams );
// Run FormB
args.name( formstr( FormB ) );
formRun = classFactory.formRunClass( Args );
formRun.init();
formrun.run();
formrun.wait();
if( formrun.closedOk() )
{
answerFromFormB.text( args.parm() );
}
super();
}The code of init method of FormB
public void init()
{
EmplTable emplTableRecord;
FormBParams formBParams;
Array items;
int i;
;
super();
// Check for passed arguments
if( element.args() )
{
// get string parameter
strValue.text( element.args().parm() );
// get enum parameter
if( element.args().parmEnumType() == EnumNum( NoYes ) )
{
NoYesEnumValue.selection( element.args().parmEnum() );
}
// get object parameter
if( element.args().parmObject() )
{
formBParams = element.args().parmObject();
items = formBParams.parmItems();
for( i=1; i<=items.lastIndex(); i++ )
{
ListBox.add( items.value(i) );
}
someDate.dateValue( formBParams.parmSomeDate() );
someTime.value( formBParams.parmSomeTime() );
}
// get record parameter
if( element.args().record() && element.args().record().TableId == TableNum( EmplTable ) )
{
emplTableRecord = element.args().record();
emplName.text( emplTableRecord.Name );
}
}
}The code of ok button click event of FromB
void clicked()
{
super();
element.args().parm( strAnswer.text() );
element.closeOk();
}The above code is cut out from a demo which you can download here.
exemple
public void printBOM(int _nodeIdx)
{
BOMTable bomTable;
MenuFunction menuFunction;
Args args = new Args();
if (!this.canPrintBOM(_nodeIdx))
{
return;
}
bomTable = node2BOMTable.lookup(_nodeIdx);
if ( bomTable.CheckBOM
&& !BOMHierarchyCheck::checkBOM(bomTable.bomId,true))
{
return;
}
startLengthyOperation();
menuFunction = new MenuFunction(menuitemOutputStr(BOMConsistOfReport), MenuItemType::Output);
args.parmObject(this);
args.parm(int2str(_nodeIdx));
menuFunction.run(args);
}
From Axaptapedia
Jump to: navigation, search
The Args system class is one of the most widely used classes in Axapta. Args is an abbreviation for arguments and an Args object is used to pass information from one object (caller) to another newly created object. Contents [hide]
1 Using Args for object creation
2 Methods and Properties
2.1 caller
2.2 record
2.3 dataset
2.4 lookupField
2.5 lookupValue
2.6 parm
2.7 parmEnum
2.8 parmEnumType
2.9 parmObject
2.10 menuItemName
2.11 menuItemType
3 Examples
[edit] Using Args for object creation
The Args object can also be used to assist in object creation, in conjunction with the ClassFactory. For example, to open a CustTable form, you can use the following code:
Args args = new Args("CustTable");
FormRun formRun = ClassFactory.formRunClass(args);
;
formRun.init();
formRun.run();
formRun.wait();[edit] Methods and Properties
[edit] caller
public Object caller( [Object _value] )
this method gets or sets the calling object. When creating an args object directly through code, the caller will not be automatically set, so you should set it yourself.
[edit] record
public Common record( [Common _value] )
this method gets or sets a table buffer (record) attached to the Args. A buffer of any table can be attached to an Args object using this method. Be aware when retrieving the buffer that there will be no compile-time check of table id. You should use the dataset method below to check the contents of the buffer.
If the caller and callee are on different tiers, then the applications will automatically copy the buffer to the target tier.
[edit] dataset
public tableId dataset()
this method gets the table Id of a table buffer (record) attached to the Args.
To safely retrieve an attached record from an Args object, use code similar to that shown below. This checks to ensure that there is an attached record, and that it is in fact a SalesTable record, before trying to assign it to the salesTable variable.
if (args.record() && args.dataset() == tableNum(SalesTable))
salesTable = args.record();
[edit] lookupField
public fieldId lookupField( [fieldId _value] )
see lookupValue
[edit] lookupValue
public str lookupValue( [str _value] )
lookupField and lookupValue are used together. When they are filled with a field Id and value, it indicates that a form opened using the current Args object will automatically select a record based on that criteria.
For example, the following code assumes that a customer with the account code "1000" exists. It will open the CustTable form with customer '1000' selected, but with the other customers still shown. This is the same result visually as is achieved using the Go to Main Table function in Axapta 3.0 and higher.
Args args = new Args("CustTable");
FormRun formRun;
;
// Look up customer 1000 when the form opens
args.lookupField(fieldNum(CustTable, AccountNum));
args.lookupValue("1000");
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();Note that this lookup is extremely fast, and should be used in preference to calling .findValue or .findRecord once the form has opened.
[edit] parm
public str parm( [str _value] )
parm is used to pass a string variable to the called object
[edit] parmEnum
public anytype parmEnum( [int _value] )
see parmEnumType
[edit] parmEnumType
public int parmEnumType( [int _value] )
parmEnum and parmEnumType are used together to pass a Base Enum value through to the called object. An example is shown below.
args.parmEnumType(EnumNum(AddressType));
args.parmEnum(AddressType::Delivery);
[edit] parmObject
public Object parmObject( [Object _value] )
parmObject is used to pass a reference to any object to the called object. Be aware of client-server issues if the caller and callee are on different tiers.
[edit] menuItemName
public final str menuItemName( [str _value] )
[edit] menuItemType
public final MenuItemType menuItemType( [MenuItemType _value] )
[edit] Examples
Passing values between forms
From Axaptapedia
Jump to: navigation, search
For passing parameters from one form to another a special class Args is usually used.
Example:
The code of button click event of FormA which calls FormB and passes some parameters to that form.
void clicked()
{
// Args class is usually used in Axapta for passing parameters between forms
Args args;
FormRun formRun;
// Our custom made class for passing complex set of parameters
FormBParams formBParams = new FormBParams();
Array items = new Array( Types::String );
int i;
;
args = new args();
// Our values which we want to pass to FormB
// If we want pass just simple string we can use 'parm' method of 'Args' class
args.parm( strValue.text() );
// We also can pass enum value to FormB
args.parmEnum( NoYesEnumValue.selection() );
args.parmEnumType( EnumNum( NoYes ) );
// and also can pass a cursor pointing to some record (in our case it is EmplTable )
args.record( EmplTable );
// If we want pass more complex set of parameters we can develop our own class
// just for passing our parameters.
formBParams.parmSomeDate( someDate.dateValue() );
formBParams.parmSomeTime( someTime.value() );
for( i=0; i<ListBox.items(); i++ )
{
items.value( i+1, ListBox.getText( i ) );
}
formBParams.parmItems( items );
// Pass our object to FormB
args.parmObject( formBParams );
// Run FormB
args.name( formstr( FormB ) );
formRun = classFactory.formRunClass( Args );
formRun.init();
formrun.run();
formrun.wait();
if( formrun.closedOk() )
{
answerFromFormB.text( args.parm() );
}
super();
}The code of init method of FormB
public void init()
{
EmplTable emplTableRecord;
FormBParams formBParams;
Array items;
int i;
;
super();
// Check for passed arguments
if( element.args() )
{
// get string parameter
strValue.text( element.args().parm() );
// get enum parameter
if( element.args().parmEnumType() == EnumNum( NoYes ) )
{
NoYesEnumValue.selection( element.args().parmEnum() );
}
// get object parameter
if( element.args().parmObject() )
{
formBParams = element.args().parmObject();
items = formBParams.parmItems();
for( i=1; i<=items.lastIndex(); i++ )
{
ListBox.add( items.value(i) );
}
someDate.dateValue( formBParams.parmSomeDate() );
someTime.value( formBParams.parmSomeTime() );
}
// get record parameter
if( element.args().record() && element.args().record().TableId == TableNum( EmplTable ) )
{
emplTableRecord = element.args().record();
emplName.text( emplTableRecord.Name );
}
}
}The code of ok button click event of FromB
void clicked()
{
super();
element.args().parm( strAnswer.text() );
element.closeOk();
}The above code is cut out from a demo which you can download here.
exemple
public void printBOM(int _nodeIdx)
{
BOMTable bomTable;
MenuFunction menuFunction;
Args args = new Args();
if (!this.canPrintBOM(_nodeIdx))
{
return;
}
bomTable = node2BOMTable.lookup(_nodeIdx);
if ( bomTable.CheckBOM
&& !BOMHierarchyCheck::checkBOM(bomTable.bomId,true))
{
return;
}
startLengthyOperation();
menuFunction = new MenuFunction(menuitemOutputStr(BOMConsistOfReport), MenuItemType::Output);
args.parmObject(this);
args.parm(int2str(_nodeIdx));
menuFunction.run(args);
}
Close methods on a form
There are “only” 5 ways to close a form:
1. Close - close the form
2. CloseOK – close the form, and set the OK flag – called by the commandbutton: Ok
3. CloseCancel – close the form, and set the Cancel flag – called by the commandbutton: Cancel
4. CloseSelectRecord – close the lookup form, and set return record
5. CloseSelect – close the lookup form, and set return value
The methods in past-tense are used to determine if or how a form was closed:
6. Closed – The form is no longer open
7. ClosedOK – The form was closed by the user clicking ‘OK’
8. ClosedCancel – The form was closed by the user clicking ‘Cancel’
And canClose() is called before any of the close methods get called.
X++ code to create and post Inventory Movement Journal
Following is the sample job to show how we can create and post movement journal by making use of available api's in the Dynamics Ax.
static void createMovJournal(Args _args)
{ InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventJournalTableData journalTableData;
InventJournalTransData journalTransData;
InventTable inventTable;
InventDim inventDim;
Counter cnt;
InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
;
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.clear();
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::Movement;
journalTable.JournalNameId = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);
journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
// Init JournalTrans
select firstonly inventTable;
for(cnt=1;cnt<10;cnt++)
{
journalTrans.clear();
journalTransData.initFromJournalTable();
journalTrans.TransDate = systemdateget() + 1 div 2;
journalTrans.ItemId = inventTable.ItemId;
journalTrans.Qty = 100;
journalTrans.CostAmount = 100;
// Dimension details
inventDim.InventLocationId = 'GW';
journalTrans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
journalTransData.create();
}
journalTable.insert();
// Call the static method to post the journal
if(InventJournalCheckPost::newPostJournal(journalTable).validate())
InventJournalCheckPost::newPostJournal(journalTable).run();
}
static void createMovJournal(Args _args)
{ InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventJournalTableData journalTableData;
InventJournalTransData journalTransData;
InventTable inventTable;
InventDim inventDim;
Counter cnt;
InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
;
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.clear();
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::Movement;
journalTable.JournalNameId = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);
journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
// Init JournalTrans
select firstonly inventTable;
for(cnt=1;cnt<10;cnt++)
{
journalTrans.clear();
journalTransData.initFromJournalTable();
journalTrans.TransDate = systemdateget() + 1 div 2;
journalTrans.ItemId = inventTable.ItemId;
journalTrans.Qty = 100;
journalTrans.CostAmount = 100;
// Dimension details
inventDim.InventLocationId = 'GW';
journalTrans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
journalTransData.create();
}
journalTable.insert();
// Call the static method to post the journal
if(InventJournalCheckPost::newPostJournal(journalTable).validate())
InventJournalCheckPost::newPostJournal(journalTable).run();
}
How to select a row in a datagrid
public void run()
{
inventJournalTable inventJournalTablefind;
super();
if(element.args())
{
if(element.args().parm())
{
select firstonly inventJournalTablefind where inventJournalTablefind.recId == str2int64(element.args().parm());
InventjournalTable_ds.findRecord(inventJournalTablefind);
}
}
}
{
inventJournalTable inventJournalTablefind;
super();
if(element.args())
{
if(element.args().parm())
{
select firstonly inventJournalTablefind where inventJournalTablefind.recId == str2int64(element.args().parm());
InventjournalTable_ds.findRecord(inventJournalTablefind);
}
}
}
How to open a form by code
A short tutorial on how to open a form in Dynamics Ax (Axapta) by code.
In the shortest example, all it takes is one line of code.
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();
The above code will open the CustTable form. That's all it takes, it's that simple.
Now if you want to supply some arguments to the opening form, this is also possible with the optional args parameter.
Like this for example:
static void OpenFormByCodeA()
{ Args args = new Args();
;
args.record(CustTable::find('ABC'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}
This code will open the CustTable form and filter out the customer with accountnumber ABC.
Use the args methods like parm and parmEnum to provide your target form with more data.
If you want even more control on opening the form from code, this is also possible.
This next example gives the same result as the previous one.
static void OpenFormByCodeB()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
Now if we tweak this a little bit, we can add our code
Like this:
static void OpenFormByCodeB()
{ Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.yourmethodgoeshere(); /* !!
formRun.run();
formRun.wait();
}
By changing the type of formRun from class FormRun to class Object, we can implement and execute extra methods on our destination form! This gives us extra possibilities for customizations. You can pass along extra parameters for example.
Only drawback: While programming, your method doesn't show up in the IntelliSense, showing all the available methods. So be carefull of typo's. (They don't give a compile error, but they will give you a run-time error.)
In the shortest example, all it takes is one line of code.
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();
The above code will open the CustTable form. That's all it takes, it's that simple.
Now if you want to supply some arguments to the opening form, this is also possible with the optional args parameter.
Like this for example:
static void OpenFormByCodeA()
{ Args args = new Args();
;
args.record(CustTable::find('ABC'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}
This code will open the CustTable form and filter out the customer with accountnumber ABC.
Use the args methods like parm and parmEnum to provide your target form with more data.
If you want even more control on opening the form from code, this is also possible.
This next example gives the same result as the previous one.
static void OpenFormByCodeB()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
Now if we tweak this a little bit, we can add our code
Like this:
static void OpenFormByCodeB()
{ Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.yourmethodgoeshere(); /* !!
formRun.run();
formRun.wait();
}
By changing the type of formRun from class FormRun to class Object, we can implement and execute extra methods on our destination form! This gives us extra possibilities for customizations. You can pass along extra parameters for example.
Only drawback: While programming, your method doesn't show up in the IntelliSense, showing all the available methods. So be carefull of typo's. (They don't give a compile error, but they will give you a run-time error.)
Where use of Extended Data Types
Update the Cross Reference from Tools -> Development tools -> Cross Reference -> periodic -> Update (It may take much time to update)
then go to the EDT -> Right Click -> Add Ins -> Cross Reference -> Used By - which will show you all the places where it has been used...
then go to the EDT -> Right Click -> Add Ins -> Cross Reference -> Used By - which will show you all the places where it has been used...
Subscribe to:
Posts (Atom)