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 Reply Children
  • 0 in reply to js-goose

    Here is how I set a date in a UDF in a script:

    retVal=oBusObj.GetValue("RequiredExpireDate$",sDate)
    retVal = oSession.FormatDate(sDate, newDate, "%M/%D/%Y")
    newDate = DateAdd("D", 25, newDate)
    newDate = oSession.GetFormattedDate(CStr(newDate))
    retVal = oBusObj.SetValue("UDF_HOUSTON_DATE$", newDate)

  • 0 in reply to js-goose

    Did you set up the UDF_RECEIVER_TIME field as a string or numeric?

    String or Number are the only two data types that the Sage 100 fields support so you have to make sure you are using the right data type in your SetValue and GetValue methods. SetValue and GetValue does not support receiving variables with the VBScript data type of Variant. You are likely to receive a hard error complaining about a data type mismatch.

    If string, then the your example should work as FormatDateTime should work since it is supposed to return a string however if you have not previously declared that currentTime will be holding a string, then this could be your problem as VBScript might be automatically assigning Variant as the data type on line 2 of your example. Any variables you use with GetValue or SetValue should first be declared with an initial value of a blank string ("") for strings and an initial value of zero (0) for numeric fields.

    If you set up the UDF_RECEIVER_TIME field as numeric, you need to remove the trailing "$" from the first argument in the SetValue method and then convert currentTime to either a Double (CDbl), Integer (CInt), or Long (CLng) data type depending on how you are planning on representing it as a time and storing it in the sage 100 UDF field. Keep in mind that since your use of FormatDateTime with the vbShortTime format, it is going to return a string with a colon separating the hours and the minutes, this is not a valid expression that can be converted to a numeric value.

  • 0 in reply to David Speck

    I'm not sure what's going on but I can't reply

  • 0 in reply to js-goose

    Every time I reply with my code I get an error and my post gets erased

  • 0 in reply to js-goose

    I encountered that a while back on another thread, very frustrating after having typed everything i did only for it to go *POOF*.

    If i remember to, i copy what i'm going to post into MS Word before submitting it just in case so i have something to recover in the event it happens again.

    Maybe try a simple post and then go back and edit it to add the code.

  • 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