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!

  • +1
    verified answer

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

  • +1 in reply to Kevin M
    verified answer

    After switching the button to run on the server, use the oBusObj handle instead of PO_ReceiptOfGoodsHeader_bus (this isn't a valid object handle in your script).

    Make sure "Allow External Access" is checked on the preferences tab of Company Maintenance for the target company.

    Also, if you are trying to store the date and time in the same format that sage 100 stores the DateUpdated and TimeUpdated fields, then you can use this handy method called GetStampInfo from oSession.

    ' Declare variables with default data type.
    sUserKey = ""
    sCurrentDate = ""
    sCurrentTime = ""
    
    ' Get stamp values.
    oSession.GetStampInfo sUserKey, sCurrentDate, sCurrentTime
    
    ' Set stamp values.
    If approved="Y" Then
        oBusObj.SetValue "UDF_RECEIVER_DATE$", sCurrentDate
        oBusObj.SetValue "UDF_RECEIVER_TIME$", sCurrentTime
        oBusObj.SetValue "UDF_RECEIVER_NAME$", oSession.UserCode
    End If

    oSession.FormatDate is used to convert a string date in YYYYMMDD format to the format specified in the third argument as the format mask.

    oSession.GetFormattedDate is used to convert a string date in another format, such as mm/dd/YYYY, in the sage 100 format, YYYYMMDD.

    Sage 100 stores time as a string data type using the decimal hours format where the number to the left of the decimal represents the hours in 24 hour format and the number to right of the decimal represents the minutes.

    ' Declare variables with default/initial data type to avoid Type Mismatch errors used with Sage 100's methods.
    sUserKey = ""
    sCurrentDate = ""
    sCurrentTime = ""
    
    ' Get stamp values.
    oSession.GetStampInfo sUserKey, sCurrentDate, sCurrentTime
    
    ' Set stamp values.
    If approved="Y" Then
        oBusObj.SetValue "UDF_RECEIVER_DATE$", sCurrentDate
        oBusObj.SetValue "UDF_RECEIVER_TIME$", sCurrentTime
        oBusObj.SetValue "UDF_RECEIVER_NAME$", oSession.UserCode
    End If

  • 0 in reply to Kevin M

    Thank you!  I had it running on the client side

  • 0 in reply to js-goose

    This works wonderfully, thank you so very much for your help!

    The only thing missing is the time is not being set when I click the button.  I implemented it exactly as you have it here though. 

    Would you mind to point me in the right direction?

    Thank you again for all of your help!

  • 0 in reply to js-goose

    I tried changing up the syntax as well but it still doesn't set - I'm sure there's something I'm missing

    CurrentDate = Now
    currentTime = FormatDateTime(CurrentDate, vbShortTime)
    
    oBusObj.SetValue "UDF_RECEIVER_TIME$",currentTime

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