Script not working correctly.

SOLVED

I have a script that is suppose to look at the date of last activity of a customer when a sales order is being written and if there is no activity for the last 720 days a message box is to pop up and let the salesperson know they are suppose to ask for new credit information. However it goes off every time no matter if it within the 720 days or not. Here is the script.

sLast = ""
sDate = ""
newDate =""
oDate =""
retVal = oBusObj.GetValue("UDF_LASTACTIVITY$", sLast)
retVal = oBusObj.GetValue("OrderDate$", sDate)
retVal = oSession.FormatDate(sLast, newDate,"%M/%D/%Y")
retVal = oSession.FormatDate(sDate, oDate,"%M/%D/%Y")
newDate = DateAdd("D",730,newDate)
if newDate < oDate then MsgBox("Please request new credit information as it has been 24 months since last activity")

 Can anyone see why it would fire every time instead of just when the difference is greater than 720.

Parents
  • 0

    Your logic is good (naming conventions not so much). Are you sure of the value in "UDF_LASTACTIVITY" is as expected? DebugPrint statements could confirm.

  • +1 in reply to connex
    verified answer

    Works now. Added the two oSession statemens and put in an End If at the end.

    sLast = ""
    sDate = ""
    newDate =""
    oDate =""
    retVal = oBusObj.GetValue("UDF_LASTACTIVITY$", sLast)
    retVal = oBusObj.GetValue("OrderDate$", sDate)
    retVal = oSession.FormatDate(sLast, newDate,"%M/%D/%Y")
    retVal = oSession.FormatDate(sDate, oDate,"%M/%D/%Y")
    newDate = DateAdd("D",730,newDate)
    newDate = oSession.GetFormattedDate(CStr(newDate))
    oDate = oSession.GetFormattedDate(CStr(oDate))
    If newDate < oDate Then MsgBox("Please request new credit information as it has been 24 months since last activity")End IF

  • 0 in reply to BigLouie
    SUGGESTED

    Your earlier version didn't work because the FormatDate function doesn't convert the variable to a date value. It converts it to a string "m/d/yyyy" from a MAS90 string "yyyymmdd". However, the DateAdd function does convert "newDate" to a date format. Thus  your "If" statement was comparing a date value in "newDate" (e.g. #5/15/2020#) to a string value in "oDate" (e.g. "5/15/2020"). When you added the two conversions using GetFormattedDate both variables where changed to the same type (a MAS90 string "yyyymmdd" and the If statement did what you wanted.

Reply
  • 0 in reply to BigLouie
    SUGGESTED

    Your earlier version didn't work because the FormatDate function doesn't convert the variable to a date value. It converts it to a string "m/d/yyyy" from a MAS90 string "yyyymmdd". However, the DateAdd function does convert "newDate" to a date format. Thus  your "If" statement was comparing a date value in "newDate" (e.g. #5/15/2020#) to a string value in "oDate" (e.g. "5/15/2020"). When you added the two conversions using GetFormattedDate both variables where changed to the same type (a MAS90 string "yyyymmdd" and the If statement did what you wanted.

Children