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.

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

Reply
  • +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

Children
No Data