Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Contributor
jryals
Posts: 37
Registered: 11-23-2008
0

Sales Order Sales Modify GL Account numbers script

[ Edited ]

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)                    'Get Current Sales Account Key

                                        Set oGLAccount = oSession.AsObject(oSession.GetObject("GL_Account_svc"))

                                        Acct = ""

                                        retVal = oGLAccount.Find(TmpSLAcct)                                                  'Find GL Account

                                        if retVal<>0 then

                                        retVal = oGLAccount.GetValue("Account$", Acct)                                 'Get Account number

                                        end if

                                        TmpNewGL = Left(Acct,4)+TmpDiv+"-0"+left(TmpType,1)                                    'Add Div and Order type to GL account number

                                        retVal = oLines.SetValue("CommentText$",TmpNewGL)                  'temp write it to comment for testing.

                                        retVal = oLines.SetValue("SalesAcctKey$", TmpNewGL, "kACCOUNT")

                                        '******* Cost of Good *********

                                        retVal = oLines.GetValue("CostOfGoodsSoldAcctKey$",TmpCOGSAcct)           'Get Current COSG Account Key

                                        Set oGLAccount = oSession.AsObject(oSession.GetObject("GL_Account_svc"))

                                        Acct = ""

                                        retVal = oGLAccount.Find(TmpCOGSAcct)                                           'Find GL Account

                                        if retVal<>0 then

                                        retVal = oGLAccount.GetValue("Account$", Acct)                                 'Get Account number

                                        end if

                                        TmpNewGL = Left(Acct,4)+TmpDiv+"-0"+left(TmpType,1)                  'Add Div and Order type to GL account number

                                        'retVal = oLines.SetValue("CommentText$",TmpNewGL)                  'temp write it to comment for testing.

                                        retVal = oLines.SetValue("CostOfGoodsSoldAcctKey$", TmpNewGL, "kACCOUNT")

                                        '*** Write Lines and move next line

                                        retval = oLines.Write()

                                        retVal = oLines.MoveNext()

                    Loop

End if