Setting Fields Based on Checkbox Click

SOLVED

Hello everyone, I'm trying to populate 3 UDFs based off a button click to approve a Receipt of Goods.  Here is the UI script I have linked to the button

'Triggered to write the date/time/name to receiver UDFs
approved=PO_ReceiptOfGoodsHeader_bus_UDF_RECEIVER_APPROVED
sDate=""
sTime=""
newDate=""

sDate = FormatDateTime(Date, vbShortDate)
sTime = FormatDateTime(Time, vbShortTime)
retVal=oSession.FormatDate(sDate, newDate, "%M/%D/%Y")
newDate=oSession.GetFormattedDate(CStr(newDate))

If approved="Y" Then
retVal=PO_ReceiptOfGoodsHeader_bus.SetValue("UDF_RECEIVER_DATE$",newDate)
retVal=PO_ReceiptOfGoodsHeader_bus.SetValue("UDF_RECEIVER_TIME$",sTime)
retVal=PO_ReceiptOfGoodsHeader_bus.SetValue("UDF_RECEIVER_NAME$", oSession.UserCode)
End If

However, when I click the button I get the following errors:

OLE Error Number: 424

Description: Object required: 'oSession'

Script Line 34 which refers to retVal=oSession.FormatDate(sDate, newDate, "%M/%D/%Y")

Any idea what I'm doing wrong?

Thanks in advance for any and all help!

Parents
  • +1
    verified answer

    Set the button script to run from the Server, so you have access to business objects.

  • 0 in reply to Kevin M

    Thank you!  I had it running on the client side

  • 0 in reply to js-goose

    Here's what I have the code set to:

    ' Triggered to write the date/time/name to receiver UDFs

    ' Declare variables
    sUserKey = ""
    sCurrentDate = ""
    sCurrentTime = ""
    CurrentDate = Now
    currentTime = ""
    retval currentTime = FormatDateTime(CurrentDate,vbShortTime)


    ' Get stamp values
    oSession.GetStampInfo sUserKey, sCurrentDate, sCurrentTime

    ' Set values on button click
    oBusObj.SetValue "UDF_RECEIVER_APPROVED$","Y"
    oBusObj.SetValue "UDF_RECEIVER_DATE$",sCurrentDate
    oBusObj.SetValue "UDF_RECEIVER_TIME$",currentTime
    oBusObj.SetValue "UDF_RECEIVER_NAME$",oSession.UserCode

  • 0 in reply to js-goose

    This line is going to cause either syntax or runtime errors.

    retval currentTime = FormatDateTime(CurrentDate,vbShortTime)

    Since you haven't stated how the UDF_RECEIVER_TIME field is set up nor how you want to store value for the current time in the UDF_RECEIVER_TIME field. I am assuming you just want it to be a string value formatted like HH:MM. 

    Since you aren't using the sUserKey and sCurrentTime variables returned from GetStampInfo, you might as well just get the current date in YYYYMMDD format from the oSession.SystemDate property instead.

    So something like this should do the trick.

    ' Triggered to write the date/time/name to receiver UDFs
    
    sCurrentTime = "" : sCurrentTime = FormatDateTime(Now, vbShortTime)
    
    ' Set values on button click
    oBusObj.SetValue "UDF_RECEIVER_APPROVED$", "Y"
    oBusObj.SetValue "UDF_RECEIVER_DATE$", oSession.SystemDate
    oBusObj.SetValue "UDF_RECEIVER_TIME$", sCurrentTime
    oBusObj.SetValue "UDF_RECEIVER_NAME$", oSession.UserCode

    Or this.

    ' Triggered to write the date/time/name to receiver UDFs
    
    sCurrentDate = "" : sCurrentDate = oSession.SystemDate
    sCurrentTime = "" : sCurrentTime = FormatDateTime(Now, vbShortTime)
    sUserCode = "" : sUserCode = oSession.UserCode
    
    ' Set values on button click
    oBusObj.SetValue "UDF_RECEIVER_APPROVED$", "Y"
    oBusObj.SetValue "UDF_RECEIVER_DATE$", sCurrentDate
    oBusObj.SetValue "UDF_RECEIVER_TIME$", sCurrentTime
    oBusObj.SetValue "UDF_RECEIVER_NAME$", sUserCode

  • 0 in reply to David Speck

    Same problem happening again :(  Even when I make a simple post and then go back to edit I get the same error.

    Hey David, you were correct in that it cause an error.  In the DB, this field is set to a varchar so I assume that's a string value.  Apologies for not knowing fully, i'm new to SAGE development and all that it entails.

    I tried both of your suggestions and they did not fill the time field on the window.  They did fill all the other fields correctly tho.

    I'm not sure why the time field is being so stubborn.  Thank you for all of your help with this, you have truly been amazing and I've learned much thus far!

  • 0 in reply to js-goose

    Use User-Defined Field and Table Maintenance to view how the field is set up.

  • 0 in reply to David Speck

    Hi David, it looks like it's set as a string - 4 characters long.  I updated my script to format the time to hhmm but for some reason it still doesn't fill the field.  Here is what my script looks like now:

    ' Triggered to write the date/time/name to receiver UDFs
    
    sTime = FormatDateTime(Time, hhmm)
    
    ' Set values on button click
    
    oBusObj.SetValue "UDF_RECEIVER_APPROVED$", "Y"
    
    oBusObj.SetValue "UDF_RECEIVER_DATE$", oSession.SystemDate
    
    oBusObj.SetValue "UDF_RECEIVER_TIME$", sTime
    
    oBusObj.SetValue "UDF_RECEIVER_NAME$", oSession.UserCode

  • 0 in reply to js-goose

    The value in your sTime variable is too long. If you test this in a simple VBScript outside of sage 100, you'll see that the value is not what you think it is and so it fails the length validation for the field.

    If you refer to the documentation for FormatDateTime, you'll see that your second argument is not valid.

    You'd be better off using the vbShortTime constant and then use Replace on the resulting value to remove the colon.

  • 0 in reply to David Speck

    WoW!  I wasn't aware I could see the VBScript outside of Sage!  Is that in a program?  If so which one?

    On a positive note, that worked!  Thank you so much; for all of your help and patience David!  Here's the final script:

    ' Triggered to write the date/time/name to receiver UDFs
    
    sTime=""
    myTime=FormatDateTime(Time, vbShortTime)
    sTime=Replace(myTime, ":", "")
    
    
    ' Set values on button click
    
    oBusObj.SetValue "UDF_RECEIVER_APPROVED$", "Y"
    
    oBusObj.SetValue "UDF_RECEIVER_DATE$", oSession.SystemDate
    
    oBusObj.SetValue "UDF_RECEIVER_TIME$", sTime
    
    oBusObj.SetValue "UDF_RECEIVER_NAME$", oSession.UserCode

  • 0 in reply to js-goose

    MS Windows ships with cscript.exe and wscript.exe. Both process VBScript files (.vbs).

    cscript.exe can send output to the console, whereas with wscript.exe, you have to either write to a text log file or display message boxes.

  • 0 in reply to David Speck

    I've learned so much today, thank you again for all of your help!  I would have been completely lost without your guidance!

  • 0 in reply to js-goose

    You're welcome.

    .vbs files can be edited with any text editor, such as Notepad, although my editor of choice is Notepad++ followed by VBSEdit.

    As long as your PC's security doesn't block the scripts, you can save the vbs file anywhere you want and double click it to have it processed by whichever script processor is the default. IIRC, windows ships with cscript.exe as the default but you can change this to wscript.exe by choosing the default program yourself. Both executables are located in the Windows\System32 folder.

    In some cases on a 64 bit version of windows, depending on what you are doing in the script, such as reading data through an ODBC source, the bit version of the script processor is important because it must match the bit version of the ODBC driver you are using to connect to the data source. You can always create a shortcut to the version of the script processor you need to use and put the full path (or relative path if shortcut and vbs file are in same directory) to your script as the first argument after the full path to the script processor in the shortcut's target.

    C:\Windows\SysWOW64\wscript.exe "FindInvalidDates.vbs"

Reply
  • 0 in reply to js-goose

    You're welcome.

    .vbs files can be edited with any text editor, such as Notepad, although my editor of choice is Notepad++ followed by VBSEdit.

    As long as your PC's security doesn't block the scripts, you can save the vbs file anywhere you want and double click it to have it processed by whichever script processor is the default. IIRC, windows ships with cscript.exe as the default but you can change this to wscript.exe by choosing the default program yourself. Both executables are located in the Windows\System32 folder.

    In some cases on a 64 bit version of windows, depending on what you are doing in the script, such as reading data through an ODBC source, the bit version of the script processor is important because it must match the bit version of the ODBC driver you are using to connect to the data source. You can always create a shortcut to the version of the script processor you need to use and put the full path (or relative path if shortcut and vbs file are in same directory) to your script as the first argument after the full path to the script processor in the shortcut's target.

    C:\Windows\SysWOW64\wscript.exe "FindInvalidDates.vbs"

Children
  • 0 in reply to David Speck

    Thank you again for the awesome info!  I use VS Code as I'm mainly a front end developer and I'm dipping my toe into SAGE/VBS/DB development for my company.

    I had no idea it was possible to run scripts like this on Windows natively.  I've set a shortcut to my scripts folder and ensured that cscript.exe is my default.  I feel like a power user now haha!

    Honestly, I cannot thank you enough for your willingness to share information, patience, and guidance.  It's really awesome, especially for someone like me who is relatively new to this world :)

  • 0 in reply to js-goose

    I suggest you take the BOI course on Sage U and also look for the scripting.docx in the KB. 

    You may also consider familiarizing yourself with the Custom Office module. You should be able to find some videos online that dive deep into it, there was a series available at one point but i don't know if it is still available. Been a while since i checked Sage U but there might be a course on there as well. Alnoor Cassim also has a lot of good samples and tips on scripting for sage 100.

    Somewhere on this forum, i have a lengthy post for people who are just getting starting with scripting for sage 100 but i've lost the link to it and can't remember the OP's subject that i posted it under.

    There are also lots of samples and examples on this forum for specific processes, such as printing a sales order through BOI, using a UDT, etc. so don't be afraid to search the forum first.