Create Fixed Asset using X++
In this blog article, we will see how we can create a Fixed Asset using code based on AssetGroupID.
Add below code in class to create a Fixed Asset,
public void createFixedAsset(AssetGroupId assetGroupId) { AssetTable assetTable; NumberSeq numberSeq; assetTable.initValue(); assetTable.assetGroup = AssetGroupId; //Initialize Number Seq for Asset Id numberSeq = assetTable.initAssetNumberSeq(assetTable.Assetgroup); AssetTable.AssetId = NumberSeq.num(); //Initialize other fields based on Asset Group assetTable.initFromAssetGroupId(assetTable.Assetgroup); //Initialize name and Name Alias fron Item Id assetTable.Name = InventTable::find('ITM1104').itemName(); assetTable.NameAlias = assetTable.Name; //Validate and Insert Fixed Asset. On insertion asset book is also created assetTable.validateWrite(); assetTable.insert(); }