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
  • +1
    verified answer

    (I'd create the accounts using Visual Integrator imports, with a batch file to repeat the imports multiple times for each of your company codes).

  • +1
    verified answer

    That particular error is associated with the Write not the SetKey. It appears you are capturing LastErrorMsg only on the Write. To be sure you are getting the SetKey error as well, change that MsgBox to something like this:

    retVal = oGLAccount.nSetKey("4143-0")
    sMsg = "2 - retVal = " & retVal
    If retVal = 0 Then sMsg = sMsg & " Last Error = " & oGLAccount.sLastErrorMsg
    MsgBox sMsg

    Having said this I agree with Kevin that V/I is a more straightforward approach. But do what your comfortable with.

  • 0 in reply to Alnoor

    Alnoor - Thanks for pointing that out and providing a recommendation. It looks like the error at the SetKey line is stating 'The main account is not on file'. I assume this to mean I need to first use the GL_MainAccount_bus class to create the main account if it does not exist. 

    I am not familiar with V/I's capabilities, but I appreciate the recommendations. Do you have any pointers on where to find resources to learn what would be needed for this task?

  • 0 in reply to acork

    Yes you are correct. The main account AND subaccounts need to exist. I would recommend getting familiar with this area of the G/L module as the best way to initially understand the requirements of the business objects it uses. A picture is word 1,000 words and "playing" in a test company trying to create your own G/L accounts through the regular UI will be valuable. So my answer to your question on resources is to actually take a different Sage U Anytime Learning course. This one called 100E - Sage 100 - Accounting Manager: Defining Accounts looks pretty good. There might be a V/I class as well.


  • 0 in reply to Alnoor

    Kevin and Alnoor - we ended up using V/I. It was a much simpler solution. Thanks!