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)

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

  • 0

    Here is an example of how I add to dates and update a field and a UDF

    sDate=""
    Ship=""
    newDate=""
    ComText= ""
    retVal=oBusObj.GetValue("RequiredExpireDate$",sDate)
    retVal=oBusObj.GetValue("ShipVia$",Ship)
    retVal=oBusObj.GetValue("Comment$",ComText)
    retVal = oSession.FormatDate(sDate, newDate, "%M/%D/%Y")
    newDate = DateAdd("D", 25, newDate)
    newDate = oSession.GetFormattedDate(CStr(newDate))
    ComText="Incoterms 2020 Apply"
    If Ship = "OCEAN" then
    retVal = oBusObj.SetValue("UDF_HOUSTON_DATE$", newDate)
    retVal = oBusObj.SetValue("Comment$",ComText)

    End If

  • 0 in reply to David Speck

    I'm actually having same issue when trying to retrive date difference (DATEDIFF) from current date (CURDATE) and issued date from one of my field. I thought my formula was wrong but seing this post it may just be reformating the date. Thank you, this is good info.