Wednesday, January 30, 2013

Record Count in Query


recordCount = sysquery::countTotal(query);

Get new number from number sequence



NumberSequenceReference numberSequenceReference;
NumberSeq               numberSeq;
;

NumberSequenceReference = numberSequenceReference::find(typeId2ExtendedTypeId(typeid(SalesId)));
numberSeq               = NumberSeq::newGetNum(NumberSequenceReference,true);
this.SalesId           = numberSeq.num();

Current empl id and sales unit of employee in AX

SmmUtility::getCurrentContact(); // current empl id
SmmUtility::getCurrentSalesUnit(); // sales unit of current employee !

Record count of tables in AX

Sometimes we need to track the record counts of tables in AX.  The fastest way is creating a query in SQL Server Management Studio.


USE Dynamics
GO
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
ORDER BY st.row_count DESC
GO

Recalculate InventSum

InventSum is needed to recalculate sometimes.We should use InventSumRecalcItem class in Dynamics AX.

Sample Code :

// CODE BEGIN ****************************

InventSumRecalcItem InventSumRecalcItem;
;
InventSumRecalcItem = new InventSumRecalcItem("ITEM001", true, checkfix::fix);
InventSumRecalcItem.updatenow();

// CODE END ******************************

First parameter : ItemId
Second parameter : Show errors
Third parameter : Fix or only check


If you want to calculate for all items :

// CODE BEGIN ****************************

InventTable InventTable;
InventSumRecalcItem InventSumRecalcItem;
;

WHILE SELECT InventTable
WHERE (InventTable.ItemType == ItemType::Item) || (InventTable.ItemType == ItemType::BOM)
{   
     InventSumRecalcItem = new InventSumRecalcItem(InventTable.ItemId, true, checkfix::fix);
     InventSumRecalcItem.updatenow();
}

// CODE END ******************************