Well, first of all, I get the error:
Error : Object reference not set to an instance of an object.
Module : salesOrder_SalesOrderLines_AddInventoryItemEnd
This was because salesOrder.GenericObjectCollection["SalesOrderForm"] was null, but perhaps that is because I don't have the rest of your code. I removed the lines:
- Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem genericItem = (JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem)salesOrder.GenericObjectCollection["SalesOrderForm"];
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)genericItem.Object;
and in their place used:
- Code: Select all
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm) salesOrder.Client;
This got me a little further, but then another error:
Error : Object reference not set to an instance of an object.
Module : AddInventoryItem
This is the error message you are getting. I had to trace through our source code to work this one out. It's a problem with the order of events firing. Here is what is happening:
1. You type a part no into the grid. This causes salesOrderForm.AddInventoryItem to be called.
2. salesOrderForm.AddInventoryItem does some checks, then calls SalesOrder.SalesOrderLines.AddInventoryItem.
3. SalesOrder.SalesOrderLines.AddInventoryItem adds the line and raises the AddInventoryItemEnd event (which is what you hook into).
4. Your code does it's thing, including possibly removing the sales order line (because you used an alternate in its place)
5. Control returns to salesOrderForm.AddInventoryItem, where it attempts to do some further checks on the new line WHICH NO LONGER EXISTS BECAUSE IT WAS REMOVED AT STEP 4!!
I'm messing around to try and deal with this in the plugin and will post back here soon.