Can anyone see an obvious mistake in this script or did I find a bug?

The ultimate goal of this is while in sales order entry  (or invoice entry) to get the sales g/l account and the cost of goods sold g/l account and modify it

I'm having no problem with the sales account (so I left that part of the code out),  but when I try to get the cost of sales account  I'm getting the sales account instead

This is tied to the sales order detail  or sales order invoice detail object

COSaccount = ""

formattedCOSaccount = ""

oCOGSGLAccount = 0

retval = obusOBJ.getvalue("CostOfGoodsSoldAcctKey$",COSaccount)  'obtain existing GL account cost of sales KEY -  this is returning a legitimate value


'now go get the formatted COS GL account by using the child handle   (originally tried a lookup with find but security rights in g/l maintenance precluded it from working unless users had access to g/l account maintenance


set oCOGSGLAccount = oSession.AsObject(oBusObj.GetChildHandle("CostofGoodsSoldAcctKey"))  'this appears to be returning the record for the sales account


retval = oCOGSGLAccount.GetValue("Account$",formattedCOSaccount)

My first thought was that the lookup for the sales account was interfering (it was looked up first).  Tried looking for the cost of sales account first,  but still got the sales account.