want to write script and put a UDF of duration between PO order date and confirm date

SUGGESTED

error using pre-write

orderdate = ""
confirmdate = ""


retVal = oBusObj.GetValue("PurchaseOrderDate$", orderdate)
retVal = oBusObj.GetValue("UDF_PO_CONFIRMDATE$", confirmdate)

dateD = DateDiff("d", confirmdate, orderdate)
retVal = oBusObj.SetValue("UDF_CONFIRM_DATE_PASS", dateD)

Parents
  • 0
    SUGGESTED

    Dates in Sage 100 are stored in YYYYMMDD format as a string.  DateDiff and CDate do not work with that format so you either have to reformat it yourself or use SY_Session's (oSession should be the object handle in the script) GetFormattedDate method.

    This is how it typically would be used.

    orderdate = ""
    confirmdate = ""
    
    
    retVal = oBusObj.GetValue("PurchaseOrderDate$", orderdate)
    retVal = oBusObj.GetValue("UDF_PO_CONFIRMDATE$", confirmdate)
    
    dateD = DateDiff("d", CDate(oSession.FormatDate(confirmdate, "%Mz/%Dz/%Y")), CDate(oSession.FormatDate(orderdate, "%Mz/%Dz/%Y")))
    retVal = oBusObj.SetValue("UDF_CONFIRM_DATE_PASS", dateD)

    If you were doing something like adding days to a date using DateAdd and needed to set the value using the new date, you would use still use the code above so VBScript's date functions will recognize the data as a valid date.  Then you would use oBusObj.SetValue "DateField$", oSession.GetFormattedDate(CStr(datevalue)).  You can optionally separately these onto separate lines if you want the value in a variable before setting it in a field.

Reply
  • 0
    SUGGESTED

    Dates in Sage 100 are stored in YYYYMMDD format as a string.  DateDiff and CDate do not work with that format so you either have to reformat it yourself or use SY_Session's (oSession should be the object handle in the script) GetFormattedDate method.

    This is how it typically would be used.

    orderdate = ""
    confirmdate = ""
    
    
    retVal = oBusObj.GetValue("PurchaseOrderDate$", orderdate)
    retVal = oBusObj.GetValue("UDF_PO_CONFIRMDATE$", confirmdate)
    
    dateD = DateDiff("d", CDate(oSession.FormatDate(confirmdate, "%Mz/%Dz/%Y")), CDate(oSession.FormatDate(orderdate, "%Mz/%Dz/%Y")))
    retVal = oBusObj.SetValue("UDF_CONFIRM_DATE_PASS", dateD)

    If you were doing something like adding days to a date using DateAdd and needed to set the value using the new date, you would use still use the code above so VBScript's date functions will recognize the data as a valid date.  Then you would use oBusObj.SetValue "DateField$", oSession.GetFormattedDate(CStr(datevalue)).  You can optionally separately these onto separate lines if you want the value in a variable before setting it in a field.

Children