Sage 100

 View Only
Expand all | Collapse all

Button Script issue with getobject

  • 1.  Button Script issue with getobject

    Posted 02-23-2021 01:14
    Hi All,
      I am struggling with the differences between an event script and a button script.  I have created a UDF on the AR Open invoice table (collections checkbox).  I am putting a button on Invoice history inquiry to check this box.  I get an error on the line to set the AR_OpenInvoice_bus.   I have tried it without parenthesis and with.  I tied separating the  asobject & getobject (was very unsure about how to do this part).   

      Any advise would be greatly appreciated.  As some point I hope to get this all straight in my head..

    'Set collections flag in open invoice records
    'Bob Osborn, ACI 2/2021
    
    sKey = "" : SDivNo = "" : sCustNo = "" : sInvNo = "" : sInvType = ""
    
    oBusObj.GetValue "ARDivisionNo$",sDivNo 
    oBusObj.GetValue "CustomerNo$", sCustNo 
    oBusObj.GetValue "InvoiceNo$", sInvNo
    oBusObj.GetValue "InvoiceType$", sInvType
    
    sKey = sDivNo & sCustNo & sInvNo & SInvType
    
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sKey)
    
    Set oAROpen = oSession.AsObject(GetObject("AR_OpenInvoice_bus")) 
    retVal = oAROpen.Find(sKey)
    retVal = oAROpen.SetValue("UDF_Collections$", Y)​


    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------


  • 2.  RE: Button Script issue with getobject

    Posted 02-23-2021 09:55
    For Advanced / Premium your button needs to be set to run from the "Server" to access business objects.

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 3.  RE: Button Script issue with getobject

    Posted 02-23-2021 09:58
    Hi Kevin,
      It is set to run from the server.  I tend to think my syntax is wrong but I see differing information.

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 4.  RE: Button Script issue with getobject

    Posted 02-23-2021 10:08
    It's always a good habit to wrap any GetObject with a permission check.
    oAROpen = oSession.GetObject("AR_OpenInvoice_bus")
    if oAROpen <> 0 then
    Set oAROpen = oSession.AsObject(oAROpen)
    else
    retVal = oSession.AsObject(oSession.UI).MessageBox("", "Access to AR_OpenInvoice_bus is required for the ... script to work.")
    'exit sub 'won't work in a button script unless you add sub tags yourself.
    end if


    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 5.  RE: Button Script issue with getobject

    Posted 02-23-2021 10:25
    Hi Kevin,   Had tried that but got errors with it as well  that was pretty much the same error message. and was trying to check my syntax on the GetObject line.   I will try again.

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 6.  RE: Button Script issue with getobject

    Posted 02-23-2021 11:23
    HI Kevin,
      I am getting on the right track now.  I was able to get it to run without errors but it was not writing.  Adding LastErrrorMsg I found that it was not in an editable state.  Writing out the SetKey values now.   

    Thanks very much for the assist Kevin!.  




    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 7.  RE: Button Script issue with getobject

    Posted 02-23-2021 12:29
    Close but no cigar...   And this is were I start to lose my mind. 

      I am getting an error 26 on the set value.  It has the last key text of UDF_COLLECTIONS.  I have tried removing the $, I have tried " retValue =SetValue "UDF_COLLECTIONS$", Y " (both with and without $.)  In all cases I get the error 26.   

      I tried moving the error test right below the SetKey to see if that was the error and 
     
    Thanks in advance...

    'Set collections flag in open invoice records
    'Bob Osborn, ACI 2/2021
    
    sKey = "" : SDivNo = "" : sCustNo = "" : sInvNo = "" : sInvType = ""
    
    oBusObj.GetValue "ARDivisionNo$",sDivNo 
    oBusObj.GetValue "CustomerNo$", sCustNo 
    oBusObj.GetValue "InvoiceNo$", sInvNo
    oBusObj.GetValue "InvoiceType$", sInvType
    
    sKey = sDivNo & sCustNo & sInvNo & SInvType
    
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sKey)
    
    oAROpen = oSession.GetObject("AR_OpenInvoice_bus")
    if oAROpen <> 0 then
      Set oAROpen = oSession.AsObject(oAROpen)
    else 
      retVal = oSession.AsObject(oSession.UI).MessageBox("", "Access to AR_OpenInvoice_bus is required for the ... script to work.")
      'exit sub 'won't work in a button script unless you add sub tags yourself.
    end if
    
    retVal = oAROpen.SetKeyValue("ARDivisionNo$", SDivNo)
    retVal = oAROpen.SetKeyValue("CustomerNo$", SCustNo)
    retVal = oAROpen.SetKeyValue("InvoiceNo$", SInvNo)
    retVal = oAROpen.SetKeyValue("InvoiceType$", SInvType)
    retVal = oAROpen.SetKey()
    retVal = oAROpen.SetValue("UDF_COLLECTIONS$", Y)
    retVal = oAROpen.Write()
    if retVal <> 1 then
         sMsg = "Script Error: " & oAROpen.LastErrorMsg
         retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    end if
    ​


    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 8.  RE: Button Script issue with getobject

    Posted 02-23-2021 15:10
    26 is a type mismatch. 

    You need to set your value with "Y"

    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------



  • 9.  RE: Button Script issue with getobject

    Posted 02-23-2021 20:11
    D'oh!  Thanks much.   Now just need to see why I don't have security rights to modify the record...

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 10.  RE: Button Script issue with getobject

    Posted 02-24-2021 10:15
    It could be because you're launching from an Inquiry screen.  I've had issues with that before.

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 11.  RE: Button Script issue with getobject

    Posted 02-24-2021 15:08
    Agree very much with what Kevin said about launching from Inquiry screen causing your security rights message. You could try converting it to a BOI script. One warning though - since the Launcher is running, regular scripting objects like oSession and oScript are in use already. Meaning in the BOI script don't use those but use equivalents object variables like oSS and oPvxScript, respectively.

    ------------------------------
    Alnoor Cassim

    Email: alnoor@asifocus.com
    Ph: 949-689-9887
    Orange County, CA
    ------------------------------



  • 12.  RE: Button Script issue with getobject

    Posted 02-24-2021 16:23
    Robert, you could try setting the program to attempt to get the session object to determine appropriate security access but you'll want to first store off what the current start task or start program is so you can set it back to that once you are done.  The alternative is to do what Alnoor said by creating a new session object through the ProvideX.Script COM object.

    Here's how you can attempt this by setting the program.
    nStartTask = 0 : nStartTask = oSession.StartTask
    ' Note, if AR_Invoice_UI doesn't work, try AR_Customer_UI
    nRetVal = 0 : nRetVal = oSession.SetProgram(oSession.LookupTask("AR_Invoice_UI")) 
    If nRetVal <> 0 Then
    	nAR_OpenInvoice_Bus = 0 : nAR_OpenInvoice_Bus = oSession.GetObject("AR_OpenInvoice_Bus")
    	If nAR_OpenInvoice_Bus <> 0 Then
    		Set oAR_OpenInvoice_Bus = oSession.AsObject(nAR_OpenInvoice_Bus)
    		' Handle you code here.
    		oAR_OpenInvoice_Bus.Clear
    		Set oAR_OpenInvoice_Bus = Nothing
    		oSession.DropObject nAR_OpenInvoice_Bus
    	End If
    End If​
    oSession.SetProgram nStartTask


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 13.  RE: Button Script issue with getobject

    Posted 02-24-2021 20:32

    HI All,

       I was concerned both about the inquiry screen as well as well as writing to AR_openinvoice.   Since I was trying to "tag" posted invoices in order to make it easy for the user, inquiry was the simplest way to 'get there"   I wound up sidestepping the issues by creating a UDT (should have realized up front that this would be needed).   Linked the table to the reports that needed it and all is well  

      Thanks to everyone for your help!   I would not be able to finish many of my scripting projects without all of you.



    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------