The following example uses day(-1) to select Customer tax invoice journal records for yesterday
Thursday, July 24, 2014
Dynamic date ranges for queries in AX
In Dynamics AX it is possible to enter dynamic date ranges for queries e.g. currentDate, day(-1) etc. which can be useful for running a daily report via a scheduled batch job.
The following example uses day(-1) to select Customer tax invoice journal records for yesterday
There are a number of dynamic data query values available in AX 2012, which can be found in the SysQueryRangeUtil class
The following example uses day(-1) to select Customer tax invoice journal records for yesterday
Wednesday, July 23, 2014
How to calculate time consumed running a process in X++
This code can be used to calculate the time consumed running a process
static void Job21(Args _args)
{
int startTime = timeNow();
int endTime;
sleep(5000);
endTime = timeNow();
info(strFmt("Process took %1", timeConsumed(startTime, endTime)));
}
Setting LedgerDimension field on LedgerJournalTrans table in AX 2012 via X++ code
The following code can be used to update LedgerDimension field on the LedgerJournalTrans
RecId getDimension(str _ledgerAccount, str _businessUnit, str _costCentre, str _jurisdiction, str _subscriberType)
{
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
if (_businessUnit)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('BusinessUnit') ;
ValueContract.parmValue(_businessUnit);
ListValueContract.addEnd(ValueContract);
}
if (_costCentre)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CostCentre') ;
ValueContract.parmValue(_costCentre);
ListValueContract.addEnd(ValueContract);
}
if (_jurisdiction)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Jurisdiction') ;
ValueContract.parmValue(_jurisdiction);
}
if (_subscriberType)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('SubscriberType') ;
ValueContract.parmValue(_subscriberType);
ListValueContract.addEnd(ValueContract);
}
LedgerAccountContract.parmMainAccount(_ledgerAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
return dimensionAttributeValueCombination.RecId;
}
Setting Default Dimension using code in AX 2012
The following method can be used to set the default dimension e.g. on CustTable when importing data via X++
static DimensionDefault findDefaultDimension(str _businessUnit, str _costCentre, str _jurisdiction, str _subscriberType)
{
Struct struct = new Struct();
container defDimensionCon;
DimensionDefault dimensionDefault;
DimensionAttributeSetItem dimAttrSetItem;
DimensionAttribute dimAttribute;
int i;
//Read required dimensions
while select Name, BackingEntityType from dimAttribute
where dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) &&
dimAttribute.Type != DimensionAttributeType::DynamicAccount
join dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttribute.RecId &&
dimAttrSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()
{
//Add the Dimension name and value to struct
if (_businessUnit && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'BusinessUnit')
{
struct.add(dimAttribute.Name, _businessUnit);
}
if (_costCentre && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'CostCentre')
{
struct.add(dimAttribute.Name, _costCentre);
}
if (_jurisdiction && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'Jurisdiction')
{
struct.add(dimAttribute.Name, _jurisdiction);
}
if (_subscriberType && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'SubscriberType')
{
struct.add(dimAttribute.Name, _subscriberType);
}
}
defDimensionCon += struct.fields();
for (i = 1; i <= struct.fields(); i++)
{
defDimensionCon += struct.fieldName(i);
defDimensionCon += struct.valueIndex(i);
}
if (struct.fields())
{
//Get the DimensionAttributeValueSet RecId
dimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defDimensionCon);
}
return dimensionDefault;
}
Subscribe to:
Posts (Atom)