I'm trying to accumulate the quantities of all the detail lines in an AR invoice, but only if the item is of a certain type. I defined a UDF for that checkbox, and put it in the Item Maintenance screen.
I would like the total to update whenever a user commits a detail line. So if they change a quantity, as soon as they leave the line I would like for the total to update.
I attached a User Defined Script to AR Invoice Detail's PostWrite event (also tried on PreWrite).
The script first gets the header, then the header gets all the lines.
We loop through the lines, and for each one we get the corresponding Item for it, so that we can check the item for the presence of the UDF.
This is where it breaks down. It's not displaying any of the properties of the item.
The script is below. Note that there are a lot of MsgBox statements in there, which we would never do in real life. But for testing purposes it helps.
' Fires on AR Invoice Detail - Post Write ' First we get all of the lines Set oLines = oSession.AsObject(oHeaderObj.Lines) totalQuantity = 0 footage = "" itemCode = "" lineItemCode = "" result = oLines.MoveFirst() Do Until oLines.EOF ' This works. result = oLines.GetValue("ItemCode$", lineItemCode) MsgBox "Item Code from detail line is " & lineItemCode ' Get the Item record for this detail line Set oItem = oSession.AsObject(oLines.GetChildHandle("ItemCode")) ' This doesn't work. In fact, none of the GetItems from the oItem work. ' Every property is blank. Note that result winds up being 1, which is no error result = oItem.GetValue("ItemCode$", itemCode) MsgBox "Item Code from item is " & itemCode result = oItem.GetValue("UDF_FOOTAGE$", footage) MsgBox "footage is " & footage ' This never gets hit, because the footage variable is never set if footage = "Y" Then MsgBox "Footage Item" qty = 0 result = oLines.GetValue("Quantity", qty) MsgBox "quantity is " & qty totalQuantity = totalQuantity + qty End If result = oLines.MoveNext() Loop MsgBox totalQuantity result = oHeaderObj.SetValue("UDF_TOTAL_FOOTAGE", totalQuantity)