I'm working on a manufacturing add-in for OA 2007. An obvious source of
increase or decrease of inventory would be when a paernt item is manufactured
and in the process a few component items are consumed. This requires me to
adjust inventory programatically (I'm working on VB .net 2003).
This is what I was trying to do:
Dim mySBAInstance As ISmallBusinessInstance
Dim myFormsFactory As IFormsFactory
Dim myCurrentItem As IInventoryItemAccount
Dim myInvAdjustment As IInventoryAdjustment
Dim myInvAdjustmentLine As IInventoryAdjustmentLine
Dim InvAdjustmentForm As Form
(I assigned the myCurrentItem to the inventory item of interest somewhere
else in the code after the variable declaration)
myInvAdjustment = mySBAInstance.CreateInventoryAdjustment()
myInvAdjustmentLine = myInvAdjustment.CreateInventoryAdjustmentLine()
myInvAdjustmentLine.InventoryItemAccount = myCurrentItem
myInvAdjustmentLine.AdjustedQuantity = (some decimal value)
myInvAdjustment.Save()
When I try to save this inventory adjustment programatically using the Save
method, I get an error message saying I this operation is not permitted
because the item has transcations.
So instead of calling the Save method of IInventoryAdjustment account I
created the OA's Inventory Adjustment Form as follows:
myFormsFactory.Initialize(mySBAInstance)
InvAdjustmentForm = myFormsFactory.CreateForm(myInvAdjustment)
InvAdjustmentForm.ShowDialog()
When I do this, the Inv Adjustment form opens up with the the entire list of
inventory items and with the assigned values of "New Qty" and "Qty
Difference" for the item of interest here. And then I go ahead and save my
quantity adjustment through the form's Save option. But bringing up another
form is not such a good idea, especially when there is a possibility that the
user could just close the form without saving the adjustment (and too many
forms popping up is not a convenient feature either).
Is there something wrong that I'm doing? My obvious suspicion is that I'm
not supposed to be using the Save method of IInventoryAdjustment class.
Please let me know if there's another way to do this programatically.
Thanks!
Shivaji.
Saving an inventory adjustment programmatically as described below should
work.
1) Is myCurrentItem saved in the database?
2) Could you please elaborate on the error message? or even copy paste the
exception message so that we can understand the issue. If you in a debugger,
you could also add the SmallBusinessException.ErrorCause value.
Thanks,
Srini
Thanks for your response.
1. Yes, myCurrentItem is saved in the databse. Infact I'm just working with
the items in the sample company databse "Northwind Traders".
2. This is the exact error message:
"Could not modify the current record because it has dependencies. (For
example, an item that apppears on one or more documents cannot be deleted.)
Shivaji.
Check out http://support.microsoft.com/kb/920193, which has some more detail
about how this is done.
You may also be able to look at the inner exception for more details.
Matthias