Error produced in vbscript when trying to create GL_Account: The record is not in an editable state.

SOLVED

I am just starting out on my Sage 100 journey to help our Sage admin automate a few processes. So, please bear with me as my knowledge is limited...

We are on Sage 100c Premium 2018 (Version 6.00.3.0)

I took the Intro to BOI class in SageU which was very helpful as it provided an example for the exact solution I am looking to develop. The only difference is that I need to be able to create the same account in over 200 companies. To get started, I want to create a single account in a test company so I procured a vbscript with the following code. As noted below, it fails when running the SetKey method for GL_Account_bus. The error I receive notes "The record is not in an editable state."

For what it is worth, I was able to successfully create a sub account using the sample code that runs just before the Account creation section. 

I can't make sense of this and would appreciate any assistance.


'Get the path to mas90\home which is required by the Init() method
Set oReg=GetObject("winmgmts:\\.\root\default:StdRegProv")
oReg.GetExpandedStringValue &H80000001,"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
PathHome = PathRoot & "\Home"
Set oReg = Nothing

Set oScript = CreateObject ("ProvideX.Script")
oScript.Init(PathHome)

Set oss = oScript.NewObject("SY_SESSION")

'The Logon method returns 1 if MAS90 Security is not enabled or if
'MAS90 has been configured to use Windows Security
retVAL = oss.nlogon()
'If the Logon method fails then you must use the SetUser method to be allowed access

If retVAL = 0 Then
    User = Trim(InputBox("Enter User Name"))
    Password = Trim(InputBox("Enter Password"))    
    retVAL = oSS.nSetUser(User,Password)
End If

'If the SetUser fails, display LastErrorMsg and quit
If retVAL = 0 Then
    MsgBox(oSS.sLastErrorMsg & vbCRLF & "Quiting")
    oSS.nCleanup()      ' Call Cleanup() before dropping the Session Object
    oSS.DropObject()
    Set oSS = Nothing
    WScript.Quit
End If

'Set MAS 90 Company and Module
'Company must be configured to Allow External Access
retVal = oss.nSetCompany("777") '777 is a test county

'If SetCompany fails, display LastErrorMsg and quit
If retVAL = 0 Then
    MsgBox(oSS.sLastErrorMsg & vbCRLF & "Quiting")
    oSS.nCleanup()      ' Call Cleanup() before dropping the Session Object
    oSS.DropObject()
    Set oSS = Nothing
    WScript.Quit
End If

TodaysDate = YEAR(Date()) & _ 
                Right("00" & Month(Date()),2) & _ 
                Right("00" & DAY(date()),2) 

retVal = oSS.nSetDate("G/L",TodaysDate)
retVal = oss.nSetModule("G/L")

'Create new GL Account
retVal = oss.nSetProgram(oss.nLookupTask("GL_Account_ui"))
Set oGLAccount = oScript.NewObject("GL_Account_bus", oss)
MsgBox("1 " & CStr(retVal))

'Use the SetKey Method from the G/L Account Maintenance Business Object
'to set the Key for the new G/L Account being created
retVal = oGLAccount.nSetKey("4143-0")
MsgBox("2 " & CStr(retVal)) ' retVal = 0 in this MsgBox, which is what is failing

'Use the SetValue method from the G/L Account Maintenance Business Object to
'set the values for the remaining G/L Account columns
retVal = oGLAccount.nSetValue("Account$","4143-0")
retVal = oGLAccount.nSetValue("AccountDesc$","YOUTH ACTIVITIES – LIVESTOCK SHOWS")
retVal = oGLAccount.nSetValue("RawAccount$","414300000")
retVal = oGLAccount.nSetValue("MainAccountCode$","4143")
retVal = oGLAccount.nSetValue("Status$","A")
retVal = oGLAccount.nSetValue("ClearBalance$","N")
retVal = oGLAccount.nSetValue("AccountType$","13")
retVal = oGLAccount.nSetValue("CashFlowsType$","N")
retVal = oGLAccount.nSetValue("AccountGroup$","4300")
retVal = oGLAccount.nSetValue("AccountCategory$","X")

'Use the Write method from the Business Object to write the record to disk
retVal = oGLAccount.nWrite()
MsgBox("5 " & CStr(retVal))
'If the G/L Account Write failed then display the last error message from
'the G/L Account Maintenance Business Object
If retVal = 0 Then
    MsgBox (oGlAccount.sLastErrorMsg)
Else
    MsgBox ("Gl Account Write complete - Script Complete")
End If

'Always destroy MAS90 Objects using the DropObject method
oGlAccount.DropObject()

' The cleanup method must be called prior to dropping the session object because
' of the recursive dependencies of the session object in other objects it creates.
oSS.nCleanup()
oSS.DropObject()

'Clear the Object Handles
'Set oGLSubAccount = Nothing
Set oGlAccount = Nothing
Set oSS = Nothing
Set oScript = Nothing
Parents Reply Children
No Data