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!

  • 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"