static void DEV_Dimension(Args _args) { SalesTable salesTable; DimensionAttributeValueSetStorage dimStorage; Counter i; salesTable = salesTable::find("SO-101282"); dimStorage = DimensionAttributeValueSetStorage::find(salesTable.DefaultDimension); //recid of 1101 for (i=1 ; i<= dimStorage.elements() ; i++) { info(strFmt("%1 = %2", DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name, dimStorage.getDisplayValueByIndex(i))); } } To get description of dimension value public Description getDimensionAttributeDesc(DimensionDefault _defaultDimension) { Description dimValue=''; DEFAULTDIMENSIONVIEW dimensionView; DimensionAttribute dimensionAttribute; select firstOnly dimensionView where dimensionView.DefaultDimension == _defaultDimension join dimensionAttribute where dimensionView.Name == dimensionAttribute.Name && dimensionView.Name == "GSECProject"; dimvalue = DimensionFinancialTag::findByFinancialTagCategoryAndValue(dimensionAttribute.financialTagCategory(), dimensionView.DisplayValue).Description; return dimValue; } |
Friday, April 25, 2014
Getting financial dimension values from DefaultDimension RecId
Wednesday, April 23, 2014
Finding current, previous and next week period through X++
static void Example_date(Args _args)
{
TransDate cwkstartDate,cwkEndDate;
TransDate lwkstartDate,lwkEndDate;
TransDate nwkstartDate,nwkEndDate;
TransDate d;
;
d = systemDateget();
cwkstartDate = Global::dateStartWk(d);
cwkEndDate = Global::dateEndWk(d) - 1;
info(strfmt("Current StartDate: %1 and EndDate: %2",cwkstartDate,cwkEndDate));
lwkstartDate = (Global::dateStartWk(d) - 7);
lwkEndDate = (Global::dateEndWk(lwkstartDate)) - 1;
info(strfmt("Lastweek StartDate: %1 and EndDate: %2",lwkstartDate,lwkEndDate));
nwkstartDate = (Global::dateStartWk(d) + 7);
nwkEndDate = (Global::dateEndWk(nwkstartDate)) - 1;
info(strfmt("Nextweek StartDate: %1 and EndDate: %2",nwkstartDate,nwkEndDate));
}
Copy the existing route details using class through coding X++ in Ax 2012
static void BOMRouteCopyJob(Args _args)
{
BOMRouteCopyJob bOMRouteCopyJob;
RouteVersion routeVersion,newRouteVersion;
RouteId fromId,newId;
InventSiteId fromSiteId;
EcoResItemConfigurationName configId;
RouteTable routeTable;
#define.item("1101")
InventTable inventTable= InventTable::find(#item);
InventDim inventDimVersion;
;
Select routeversion where
routeversion.ItemId == #item &&
(routeversion.Approved == Noyes::Yes &&
routeversion.Active == Noyes::Yes);
fromId = routeversion.RouteId;
configId = routeVersion.configId();
fromSiteId = routeversion.inventSiteId();
if (routeversion)
{
//Create a new route
newId = fromId + "/333" ;
routeTable.RouteId = newId;
routeTable.ItemGroupId = inventTable.itemGroupId();
routeTable.insert();
//Create a route version
newRouteVersion.initFromRouteTable(routeTable);
newrouteversion.initFromInventTable(inventTable);
inventDimVersion.InventSiteId = fromSiteId;
newRouteVersion.InventDimId = InventDim::findOrCreate(inventDimVersion).inventDimId;
newrouteversion.insert();
}
//Copy the route details from another route
bOMRouteCopyJob = BOMRouteCopyJob::construct();
bOMRouteCopyJob.parmFromRouteId(fromId);
bOMRouteCopyJob.parmToRouteId(newId);
bOMRouteCopyJob.checkBaseData();
bOMRouteCopyJob.parmFromItemId(#item);
bOMRouteCopyJob.parmToItemId(#item);
bOMRouteCopyJob.parmToSiteId(fromSiteId);
bOMRouteCopyJob.parmFromSiteId(fromSiteId);
bOMRouteCopyJob.parmCopyRoute(true);
bOMRouteCopyJob.run();
}
Tuesday, April 15, 2014
Using Currency Exchange Helper class
static void SR_CEH_Example1(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = 'EUR';
AmountCur amountCur = 500.00;
AmountMst amountMST;
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt('%1',amountMST));
}
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = 'EUR';
AmountCur amountCur = 500.00;
AmountMst amountMST;
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt('%1',amountMST));
}
Friday, April 4, 2014
Using Temp Table
1. Create temp table with property In Memory or TempDB
2. public void init()
{
HRMAbsenceTable hrmAbsenceTable;
HRMAbsenceTrans hrmAbsenceTrans;
A_AbsenceBalances _a_AbsenceBalances; //temp table (In Memory)
super();
while select sum(Hours),PostedDate,TransDate,
HRMAbsenceCodeId,
hrmAbsenceCodeGroupId
from hrmAbsenceTrans
group by PostedDate,hrmAbsenceTrans.TransDate,
HRMAbsenceCodeId,
hrmAbsenceCodeGroupId
join hrmAbsenceTable
where hrmAbsenceTable.hrmAbsenceTableId==hrmAbsenceTrans.hrmAbsenceTableId
{
_a_AbsenceBalances.Approve=HcmWorker::find(HRMAbsenceTable::find(hrmAbsenceTrans.hrmAbsenceTableId).Worker_ApprovedBy).name();
_a_AbsenceBalances.status=hrmAbsenceTable.status;
_a_AbsenceBalances.PostedDate=hrmAbsenceTrans.PostedDate;
_a_AbsenceBalances.transDate=hrmAbsenceTrans.transDate;
_a_AbsenceBalances.TransferredDate=hrmAbsenceTrans.TransferredDate;
_a_AbsenceBalances.TransferToPay=hrmAbsenceTrans.TransferToPay;
_a_AbsenceBalances.transText=hrmAbsenceTrans.transText;
_a_AbsenceBalances.hrmAbsenceCodeGroupId=hrmAbsenceTrans.hrmAbsenceCodeGroupId;
_a_AbsenceBalances.hrmAbsenceCodeId=hrmAbsenceTrans.hrmAbsenceCodeId;
_a_AbsenceBalances.hrmAbsenceTableId=hrmAbsenceTrans.hrmAbsenceTableId;
_a_AbsenceBalances.IsTransToPay=hrmAbsenceTrans.IsTransToPay;
_a_AbsenceBalances.Name=hrmAbsenceTrans.Name;
_a_AbsenceBalances.hours=hrmAbsenceTrans.hours;
_a_AbsenceBalances.PayType=hrmAbsenceTrans.PayType;
_a_AbsenceBalances.Worker=hrmAbsenceTable.worker;
_a_AbsenceBalances.doInsert();
}
A_AbsenceBalances.setTmp();
A_AbsenceBalances.setTmpData(_a_AbsenceBalances);
A_AbsenceBalances_ds.executeQuery();
}
2. public void init()
{
HRMAbsenceTable hrmAbsenceTable;
HRMAbsenceTrans hrmAbsenceTrans;
A_AbsenceBalances _a_AbsenceBalances; //temp table (In Memory)
super();
while select sum(Hours),PostedDate,TransDate,
HRMAbsenceCodeId,
hrmAbsenceCodeGroupId
from hrmAbsenceTrans
group by PostedDate,hrmAbsenceTrans.TransDate,
HRMAbsenceCodeId,
hrmAbsenceCodeGroupId
join hrmAbsenceTable
where hrmAbsenceTable.hrmAbsenceTableId==hrmAbsenceTrans.hrmAbsenceTableId
{
_a_AbsenceBalances.Approve=HcmWorker::find(HRMAbsenceTable::find(hrmAbsenceTrans.hrmAbsenceTableId).Worker_ApprovedBy).name();
_a_AbsenceBalances.status=hrmAbsenceTable.status;
_a_AbsenceBalances.PostedDate=hrmAbsenceTrans.PostedDate;
_a_AbsenceBalances.transDate=hrmAbsenceTrans.transDate;
_a_AbsenceBalances.TransferredDate=hrmAbsenceTrans.TransferredDate;
_a_AbsenceBalances.TransferToPay=hrmAbsenceTrans.TransferToPay;
_a_AbsenceBalances.transText=hrmAbsenceTrans.transText;
_a_AbsenceBalances.hrmAbsenceCodeGroupId=hrmAbsenceTrans.hrmAbsenceCodeGroupId;
_a_AbsenceBalances.hrmAbsenceCodeId=hrmAbsenceTrans.hrmAbsenceCodeId;
_a_AbsenceBalances.hrmAbsenceTableId=hrmAbsenceTrans.hrmAbsenceTableId;
_a_AbsenceBalances.IsTransToPay=hrmAbsenceTrans.IsTransToPay;
_a_AbsenceBalances.Name=hrmAbsenceTrans.Name;
_a_AbsenceBalances.hours=hrmAbsenceTrans.hours;
_a_AbsenceBalances.PayType=hrmAbsenceTrans.PayType;
_a_AbsenceBalances.Worker=hrmAbsenceTable.worker;
_a_AbsenceBalances.doInsert();
}
A_AbsenceBalances.setTmp();
A_AbsenceBalances.setTmpData(_a_AbsenceBalances);
A_AbsenceBalances_ds.executeQuery();
}
Thursday, April 3, 2014
OR condition in X++ Query Range
Adding OR condition in X++ query range
public void executeQuery()
{
list list = new list(types::String);
listenumerator listenumerator;
query q;
querybuilddatasource qbds;
;
list.addEnd(SalesStatus::Delivered);
list.addEnd(SalesStatus::Invoiced);
qbds = this.query().dataSourceNo(1);
listenumerator = list.getEnumerator();
while(listenumerator.moveNext())
{
qbds.addRange(fieldnum(SalesTable,SalesStatus)).value(queryvalue(listenumerator.current()));
}
info(this.query().dataSourceNo(1).toString());
super();
}
public void executeQuery()
{
list list = new list(types::String);
listenumerator listenumerator;
query q;
querybuilddatasource qbds;
;
list.addEnd(SalesStatus::Delivered);
list.addEnd(SalesStatus::Invoiced);
qbds = this.query().dataSourceNo(1);
listenumerator = list.getEnumerator();
while(listenumerator.moveNext())
{
qbds.addRange(fieldnum(SalesTable,SalesStatus)).value(queryvalue(listenumerator.current()));
}
info(this.query().dataSourceNo(1).toString());
super();
}
Subscribe to:
Posts (Atom)