This blog discusses tips that would be useful in Microsoft Dynamics AX! I have made a note of all pointers that I thought would prove to be useful for someone at some point in future! Please feel free to drop in your comments and feedback on any article here!

mardi 30 août 2011
vendredi 12 août 2011
How and use close method in a form
Called when a form is closed.
Here is an example when closing a form according to records in a grid of a table we update records in another table.
public void close()
{
ThyProjForcasTable ProjForcasTable;
;
super();
ttsbegin;
while select ProjForcasTable
where ProjForcasTable.ProjId == ThyProjForcasTable.ProjId
{
if (ProjForcasTable.NoYesId == NoYes::No)
{
select forupdate projTable
where projTable.ProjId == ThyProjForcasTable.ProjId;
Projtable.Status = ProjStatus::Created;
Projtable.update();
}
}
ttscommit;
}
{
ThyProjForcasTable ProjForcasTable;
;
super();
ttsbegin;
while select ProjForcasTable
where ProjForcasTable.ProjId == ThyProjForcasTable.ProjId
{
if (ProjForcasTable.NoYesId == NoYes::No)
{
select forupdate projTable
where projTable.ProjId == ThyProjForcasTable.ProjId;
Projtable.Status = ProjStatus::Created;
Projtable.update();
}
}
ttscommit;
}
jeudi 11 août 2011
How to oblige a window to be called with parameters
Here is the code:
public void init()
{;
super();
if (!element.args().caller())
{
// Window must be called with parameters.
throw error("@SYS22539");
}
purchReqTableForm = element.args().caller();
}
mercredi 10 août 2011
How to get relation between inventSerial and inventTrans
From from InventTransId, I can get InventDimId and from InventDimId and, from InventDimId I can get InventSerialId, but that's not reversible :
// Changed on 08 Aoû 2011 at 12:33:54 by iba
void clicked()
{
Args args;
InventTrans inventTrans;
InventDim inventDim;
inventDimId _inventDimId;
InventSerial _inventSerial;
InventTransType InventTransType;
;
dialog = new Dialog();
dialog.caption("@THY47");
thy_InventVendNum = dialog.addField(typeId(Thy_InventVendNum));
_inventVendNum = InventSerial.thy_InventVendNum;
inventSerialId = InventSerial.InventSerialId;
itemId = InventSerial.ItemId;
thy_InventVendNum.value(_inventVendNum);
if (dialog.run())
{
ttsbegin;
while select inventDimId from inventDim
where inventDim.inventSerialId == inventSerial.InventSerialId
{
while select forupdate Thy_InventVendNum, CustVendAC, inventtransid from InventTrans index hint TransIdIdx
where InventTrans.inventDimId == inventDim.inventDimId
&& InventTrans.TransType == InventTransType::Purch
{
if (!InventTrans::Thy_existThy_InventVendNum(thy_InventVendNum.value(),
InventTrans.CustVendAC)
|| thy_InventVendNum.value() == '' )
{
InventTrans.Thy_InventVendNum = thy_InventVendNum.value();
InventTrans.update();
select forupdate firstOnly Thy_InventVendNum from _inventSerial
index hint ItemSerialIdx
where _inventSerial.InventSerialId == inventSerialId
&& _inventSerial.ItemId == itemId;
_inventSerial.Thy_InventVendNum = thy_InventVendNum.value();
_inventSerial.update();
inventSerial_DS.research();
break;
}
else
{
error(strfmt( "@THY73" ,thy_InventVendNum.value(), InventTrans.CustVendAC));
}
}
}
ttscommit;
}
super();
}
void clicked()
{
Args args;
InventTrans inventTrans;
InventDim inventDim;
inventDimId _inventDimId;
InventSerial _inventSerial;
InventTransType InventTransType;
;
dialog = new Dialog();
dialog.caption("@THY47");
thy_InventVendNum = dialog.addField(typeId(Thy_InventVendNum));
_inventVendNum = InventSerial.thy_InventVendNum;
inventSerialId = InventSerial.InventSerialId;
itemId = InventSerial.ItemId;
thy_InventVendNum.value(_inventVendNum);
if (dialog.run())
{
ttsbegin;
while select inventDimId from inventDim
where inventDim.inventSerialId == inventSerial.InventSerialId
{
while select forupdate Thy_InventVendNum, CustVendAC, inventtransid from InventTrans index hint TransIdIdx
where InventTrans.inventDimId == inventDim.inventDimId
&& InventTrans.TransType == InventTransType::Purch
{
if (!InventTrans::Thy_existThy_InventVendNum(thy_InventVendNum.value(),
InventTrans.CustVendAC)
|| thy_InventVendNum.value() == '' )
{
InventTrans.Thy_InventVendNum = thy_InventVendNum.value();
InventTrans.update();
select forupdate firstOnly Thy_InventVendNum from _inventSerial
index hint ItemSerialIdx
where _inventSerial.InventSerialId == inventSerialId
&& _inventSerial.ItemId == itemId;
_inventSerial.Thy_InventVendNum = thy_InventVendNum.value();
_inventSerial.update();
inventSerial_DS.research();
break;
}
else
{
error(strfmt( "@THY73" ,thy_InventVendNum.value(), InventTrans.CustVendAC));
}
}
}
ttscommit;
}
super();
}
mardi 9 août 2011
How to select the last record in a table
select firstOnly * from VendPurchOrderJour order by recid desc ;
mardi 2 août 2011
How to insert Data into LedgerJournalTrans and LedgerJournalTrans_Asset
Here is an example of a job
// Changed on 22 Jui 2011 at 17:28:00 by ibs
static void Import_Immobilisations(Args _args)
{
LedgerJournalTrans_Asset ledgerJournalTrans_Asset;
container c;
AssetledgerAccounts assetledgerAccounts;
TextIo io;
String50 filename;
AssetTransType assetTransType;
LedgerJournalTrans ledgerJournalTrans, LedgerJournalTrans_Update;
AssetTransTypeJournal assetTransTypeJournal;
AssetId assetId;
AssetBookId assetBookId;
AssetTransType TransType;
String30 stringdate;
ExchRates ExchRates;
LedgerJournalNameId LedgerJournalNameId;
NumberSeq numSeq1, numSeq2;
Voucher Voucher1, Voucher2 ;
LedgerJournalACType LedgerJournalACType;
AssetGroupId AssetGroupId;
TextBuffer amount;
;
delete_from LedgerJournalTrans_Asset where LedgerJournalTrans.createdBy =='ibs';
delete_from LedgerJournalTrans where LedgerJournalTrans.createdBy =='ibs';
amount = new TextBuffer();
fileName = @"C:\\IMMOB\IMMOBILISATIONS_I.csv";
io = SysLicenseCodeReadFile::openFile(fileName,'r');
if (!io)
throw error(strfmt("@SYS18678",fileName));
io.inFieldDelimiter(";");
c = io.read();
numSeq1 = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find('Invest').VoucherSeries, true );
numSeq2 = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find('Invest_I').VoucherSeries, true );
Voucher1 = numSeq1.voucher();
Voucher2 = numSeq2.voucher();
numSeq1.used();
numSeq2.used();
while (io.status() == IO_Status::Ok)
{
c = io.read();
if (io.status() != IO_Status::Ok)
break;
assetBookId = conpeek(c,1);
assetId = conpeek(c,4);
stringdate = conpeek(c,7);
assetTransType = AssetTransType::Acquisition;
AssetGroupId = conpeek(c,2);
if (LedgerJournalTrans::findAssetId(assetId, true).RecId == 0 && assetId != '' )
{
if( conpeek(c,5) == '1' )
{
LedgerJournalNameId = 'Invest';
LedgerJournalTrans.JournalNum = LedgerJournalTable::findByName(LedgerJournalNameId).JournalNum;
LedgerJournalTrans.Voucher = Voucher1;
}
else
{
LedgerJournalNameId = 'Invest_I';
LedgerJournalTrans.JournalNum = LedgerJournalTable::findByName(LedgerJournalNameId).JournalNum;
LedgerJournalTrans.Voucher = Voucher2;
}
ledgerJournalTrans.Company = curext();
LedgerJournalTrans.currencyCode = 'TND';
LedgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
LedgerJournalTrans.AccountNum = assetId;
LedgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets;
LedgerJournalTrans_Asset.BookId = assetBookId;
LedgerJournalTrans.Txt = conpeek(c,6);
amount.setText(conpeek(c,8));
amount.replace(',','.');
LedgerJournalTrans.AmountCurDebit = str2num(amount.getText());
LedgerJournalTrans.TransDate = str2date(stringdate,123);
LedgerJournalTrans.OffsetAccount = AssetLedgerAccounts::findLedgerAccount(assetBookId,"IMMOB",assetTransType).LedgerOffsetAccount;
// LedgerJournalTrans.OffsetAccount = AssetLedgerAccounts::find(assetBookId,"IMMOB",assetTransType,TableGroupAll::GroupId,AssetGroupId).LedgerOffsetAccount;
LedgerJournalTrans.Qty = str2num(conpeek(c,5));
LedgerJournalTrans.PostingProfile = "IMMOB";
LedgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.currencyCode);
LedgerJournalTrans.insert();
select recId, Company from LedgerJournalTrans_Update where LedgerJournalTrans_Update.RecId == LedgerJournalTrans.RecId;
if ( LedgerJournalTrans_Asset::find(LedgerJournalTrans_Update.RecId).RefRecId == 0)
{
LedgerJournalTrans_Asset.AssetId = assetId;
LedgerJournalTrans_Asset.BookId = assetBookId;
LedgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition;
LedgerJournalTrans_Asset.RefRecId = ledgerJournalTrans.RecId;
ledgerJournalTrans_Asset.Company = LedgerJournalTrans_Update.Company;
LedgerJournalTrans_Asset.insert();
}
print 'inserted';
}
}
info("finished");
}
// Changed on 22 Jui 2011 at 17:28:00 by ibs
static void Import_Immobilisations(Args _args)
{
LedgerJournalTrans_Asset ledgerJournalTrans_Asset;
container c;
AssetledgerAccounts assetledgerAccounts;
TextIo io;
String50 filename;
AssetTransType assetTransType;
LedgerJournalTrans ledgerJournalTrans, LedgerJournalTrans_Update;
AssetTransTypeJournal assetTransTypeJournal;
AssetId assetId;
AssetBookId assetBookId;
AssetTransType TransType;
String30 stringdate;
ExchRates ExchRates;
LedgerJournalNameId LedgerJournalNameId;
NumberSeq numSeq1, numSeq2;
Voucher Voucher1, Voucher2 ;
LedgerJournalACType LedgerJournalACType;
AssetGroupId AssetGroupId;
TextBuffer amount;
;
delete_from LedgerJournalTrans_Asset where LedgerJournalTrans.createdBy =='ibs';
delete_from LedgerJournalTrans where LedgerJournalTrans.createdBy =='ibs';
amount = new TextBuffer();
fileName = @"C:\\IMMOB\IMMOBILISATIONS_I.csv";
io = SysLicenseCodeReadFile::openFile(fileName,'r');
if (!io)
throw error(strfmt("@SYS18678",fileName));
io.inFieldDelimiter(";");
c = io.read();
numSeq1 = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find('Invest').VoucherSeries, true );
numSeq2 = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find('Invest_I').VoucherSeries, true );
Voucher1 = numSeq1.voucher();
Voucher2 = numSeq2.voucher();
numSeq1.used();
numSeq2.used();
while (io.status() == IO_Status::Ok)
{
c = io.read();
if (io.status() != IO_Status::Ok)
break;
assetBookId = conpeek(c,1);
assetId = conpeek(c,4);
stringdate = conpeek(c,7);
assetTransType = AssetTransType::Acquisition;
AssetGroupId = conpeek(c,2);
if (LedgerJournalTrans::findAssetId(assetId, true).RecId == 0 && assetId != '' )
{
if( conpeek(c,5) == '1' )
{
LedgerJournalNameId = 'Invest';
LedgerJournalTrans.JournalNum = LedgerJournalTable::findByName(LedgerJournalNameId).JournalNum;
LedgerJournalTrans.Voucher = Voucher1;
}
else
{
LedgerJournalNameId = 'Invest_I';
LedgerJournalTrans.JournalNum = LedgerJournalTable::findByName(LedgerJournalNameId).JournalNum;
LedgerJournalTrans.Voucher = Voucher2;
}
ledgerJournalTrans.Company = curext();
LedgerJournalTrans.currencyCode = 'TND';
LedgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
LedgerJournalTrans.AccountNum = assetId;
LedgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets;
LedgerJournalTrans_Asset.BookId = assetBookId;
LedgerJournalTrans.Txt = conpeek(c,6);
amount.setText(conpeek(c,8));
amount.replace(',','.');
LedgerJournalTrans.AmountCurDebit = str2num(amount.getText());
LedgerJournalTrans.TransDate = str2date(stringdate,123);
LedgerJournalTrans.OffsetAccount = AssetLedgerAccounts::findLedgerAccount(assetBookId,"IMMOB",assetTransType).LedgerOffsetAccount;
// LedgerJournalTrans.OffsetAccount = AssetLedgerAccounts::find(assetBookId,"IMMOB",assetTransType,TableGroupAll::GroupId,AssetGroupId).LedgerOffsetAccount;
LedgerJournalTrans.Qty = str2num(conpeek(c,5));
LedgerJournalTrans.PostingProfile = "IMMOB";
LedgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.currencyCode);
LedgerJournalTrans.insert();
select recId, Company from LedgerJournalTrans_Update where LedgerJournalTrans_Update.RecId == LedgerJournalTrans.RecId;
if ( LedgerJournalTrans_Asset::find(LedgerJournalTrans_Update.RecId).RefRecId == 0)
{
LedgerJournalTrans_Asset.AssetId = assetId;
LedgerJournalTrans_Asset.BookId = assetBookId;
LedgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition;
LedgerJournalTrans_Asset.RefRecId = ledgerJournalTrans.RecId;
ledgerJournalTrans_Asset.Company = LedgerJournalTrans_Update.Company;
LedgerJournalTrans_Asset.insert();
}
print 'inserted';
}
}
info("finished");
}
Inscription à :
Articles (Atom)