- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Sales Order Sales Modify GL Account numbers script
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-18-2012 04:16 PM - last edited on 01-18-2012 04:21 PM
I've created a script to loop through the sales order lines and modify the sales and cost of goods account based on the AR Division and a user defined field for Order Type 1=Sales 2=Service and 3=Rental. It is triggered after a change in the division or the user defined field. Works like a charm.
Here is the code:
If oSession.CompanyCode = "ABC" Then
Msg = "Change Order Type GL update"
retval = oSession.AsObject(oSession.UI).Messagebox("",Msg)
'**** This script get the order type then loops through the lines and modifies the Sales and COGS GL account numbers ****
oGlAccount = 0
oLines = 0
TmpGL = ""
TmpType = ""
TmpNewGL = ""
TmpSLAcct = ""
TmpCOGSAcct = ""
TmpDiv = ""
'
retVal = oBusObj.GetValue("ARDivisionNo$",TmpDiv) 'Get Division No
retVal = oBusObj.GetValue("UDF_TYPE$",TmpType) 'Get Order Type 1=Sales 2=Service 3=Rental
'**** Start loop *****
Set oLines = oBusObj.AsObject(oBusObj.Lines)
retVal = oLines.MoveFirst()
do until oLines.Eof
'******* Sales *********
retVal = oLines.GetValue("SalesAcctKey$",TmpSLAcct)
Set oGLAccount = oSession.AsObject(oSession.GetObject("GL_Account_s
Acct = ""
retVal = oGLAccount.Find(TmpSLAcct)
if retVal<>0 then
retVal = oGLAccount.GetValue("Account$", Acct) 'Get Account number
end if
TmpNewGL = Left(Acct,4)+TmpDiv+"-0"+left(TmpType,1)
retVal = oLines.SetValue("CommentText$",TmpNewGL)
retVal = oLines.SetValue("SalesAcctKey$", TmpNewGL, "kACCOUNT")
'******* Cost of Good *********
retVal = oLines.GetValue("CostOfGoodsSoldAcctKey$",TmpCOGSA
Set oGLAccount = oSession.AsObject(oSession.GetObject("GL_Account_s
Acct = ""
retVal = oGLAccount.Find(TmpCOGSAcct)
if retVal<>0 then
retVal = oGLAccount.GetValue("Account$", Acct) 'Get Account number
end if
TmpNewGL = Left(Acct,4)+TmpDiv+"-0"+left(TmpType,1)
'retVal = oLines.SetValue("CommentText$",TmpNewGL)
retVal = oLines.SetValue("CostOfGoodsSoldAcctKey$", TmpNewGL, "kACCOUNT")
'*** Write Lines and move next line
retval = oLines.Write()
retVal = oLines.MoveNext()
Loop
End if


