Alternative items in production

I do not quite understand why the alternative item functionality is only available for sales not for production. Consider the following scenario: Cream typically is bought in small volumes at around $3.00 per KG. A large order of a special product might allow us to buy larger volumes at say $2.00 per KG. The price of the standard cream should not be change for the costing of standard jobs because when the large job ceases, the small jobs need to pay for themselves.
An easy solution would be the use of an alternative item with an independent price, but of course the the two items can be used interchangeably on the shopfloor.
A small mod in one of the ProdUpd… classes (e.g. ProdUpdStartup.updateBOMConsumption()) activates alternative items for production. It functions by checking the availablility of the BOMItems when starting the job. Depending on the configuration it might be more appropriatly placed in another of ther ProdUpd… classes.
void updateBOMConsumption()
    Container                   c; //bw
    ItemId                      altItemId;    //bw
    InventDim                   altInventDim; //bw
            prodBOM = recListProdBOM.peek();
                loop =;
//bw start
//Changed on 30 Apr 2007 by TW
/* Description:
Allow for alternative ingredients
           //only if not yet consumed and no specific dimension has been assigned
           if(prodBOM.QtyInventCalc == prodBOM.RemainInventPhysical
              && (!prodBom.InventDimId || prodBom.InventDimId == InventDim::inventDimIdBlank()))
                // use standard method to find an alternative item for the desired qty.
                c = InventTable::findAlternativeItem(prodBom.ItemId,prodBom.InventDim(),prodBom.QtyInventCalc);
                if (c)
                    altItemId = conpeek(c,1);
                    altInventDim = conpeek(c,2);
                    prodBom.ItemId = altItemId;
                    if (altInventDim)
                        prodBom.InventDimId = altInventDim.inventDimId;
                        prodBom.InventDimId = InventDim::inventDimIdBlank();
//bw end
            prodBOMCalc = ProdBOMCalc::newBOMCalcData(BOMCalcData,

Allow changing of Inventory UnitId

Dynamics Ax does not allow you to change the Inventory UnitId of an item if there is stock or if there are open transactions. We as a food business wanted to change the inventory unit of canola oil from 200L barrels to 1000L Pallecons (or even better to Ltrs, avoiding future changes of the Inventory Stock Item), but as nearly every one of our products use canola oil the will be no point in time without open transactions (production orders) and deleting and reentering all open orders is also a nuisance. Therefore I decided to make a mod which allows us to change to unitId with open transactions and existing stock. The modifications only need to be done in the update method of the InventTableModule table and are marked with //bw.
IMPORTANT: The code here only updates InventTrans and InventSum. There are other tables with Quantities referring to the Inventory Unit such as InventJournalTrans which I do not update. This leads to inconsistencies which we can live with but you might not!
void update(boolean _updatePriceDate = true)
    InventTrans inventTrans;                //bw
    InventTableModule   old = this.orig();  //bw
    InventSum   inventSum;                  //bw
    boolean updPrice;
    FormRun         formRun;
    FormObjectSet   formObjSet;
    int     i;
    if (this.orig().Price     != this.Price     ||
        this.orig().Markup    != this.Markup    ||
        this.orig().PriceUnit != this.PriceUnit)
        updPrice        = true;
        if (_updatePriceDate)
            this.PriceDate  = systemdateget();
//bw start
//Changed on 27 Apr 2007 by TW
/* Description:
allow update of units: modify stock level and inventJournals
Prerequisite: a unit conversion must exist between the old and the new UnitId.
The unit conversion will be used to adjust the quantities.
    if (old.UnitId != this.UnitId && this.ModuleType==ModuleInventPurchSales::Invent) //only for inventory type
        if(UnitConvert::canConvert(old.UnitId,this.UnitId,this.ItemId)//assured by validateField
            && UnitConvert::valueConvert(1,old.UnitId,this.UnitId,this.ItemId)!=1) //only bother if not one-to-one
            //adjust inventTrans (this updates all transaction history of the item and might take a while)
            while select forupdate inventTrans where inventTrans.ItemId == this.ItemId
                inventTrans.Qty = UnitConvert::valueConvert(inventTrans.Qty,old.UnitId,this.UnitId,this.ItemId);
                inventTrans.QtySettled = 
            //adjust inventSum
            select forupdate firstonly inventSum where inventSum.ItemId == this.ItemId;
            if (inventSum)
                    = UnitConvert::valueConvert(inventSum.AvailOrdered,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.AvailPhysical,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.OnOrder,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Ordered,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.ReservOrdered,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.ReservPhysical,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Received,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.PostedQty,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Deducted,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.QuotationIssue,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.QuotationReceipt,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Registered,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Picked,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.Arrived,old.UnitId,this.UnitId,this.ItemId);
                    = UnitConvert::valueConvert(inventSum.PhysicalInvent,old.UnitId,this.UnitId,this.ItemId);
//bw end

    if (updPrice)


Restore Sharepoint WSS 2 Database

I was trying to upgrade to WSS 3 and something failed so I wanted to return to WSS 2 so I reinstalled WSS 2 and tried to attached my backuped databases. I received the "Database ‘Database_Name’ already exists. (Error code:1801)" error message which I could resolve by following KB828815. But then I received the a further error message which seemed to reflect a version confilct that I could not solve. So I decided to copy the database manually with the following steps:
  1. Create a New Site (including new content database e.g. STS_new_234)
  2. Use the SQL Server management studio to attach/restore the old content database e.g. STS_old_123)
  3. Get the new SiteId from the [STS_new_234].[dbo].[Sites] e.g. {61806ab3-c940-4867-8f5a-629c0036e6bd}
  4. Copy the data of all tables (exept Sites) from the STS_old_123 to STS_new_234 and rename the field SiteId to the new SiteId in the process e.g.
    INSERT INTO [STS_new_234].[dbo].[NavNodes]
    SELECT ‘61806ab3-c940-4867-8f5a-629c0036e6bd’
      FROM [STS_old_123].[dbo].[NavNodes]

    Note: The most important tables: Docs, Links, NavNodes, UserData, UserInfo, WebCat
  5. Modify the [STS_new_234].[dbo].[Webs]:
    • First make the old root a sub-site by editing FullUrl and setting ParentWebId to the new root.
    • If all is now well try and exchange the new root with the old root (again by editing FullUrl and ParentWebId accordingly).

NOTE: The whole issue probably could have been avoided by running PRESCAN on all the existing databases BEFORE starting to upgrade.