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.

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

  • 0 in reply to connex

    Hey Connex, how are you! Long time. Yes everything returns correct value. If I put in a MsgBox at the end both newDate and oDate return correct values correctly formatted. It is just that the message box comes up no matter if newDate is less than oDate or if newDate is greater than oDate.

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

  • 0 in reply to connex

    Well it ran just find on the server where I was remoting into. When they try to run on a work station it freezes everything up. What could be stopping it?

  • 0 in reply to BigLouie

    You cannot use MsgBox on a workstation because the message goes to the server and hangs it.  You have to use ".MessageBox".

  • 0 in reply to connex

    Yea, Elliott said the same thing and I  noticed I am not checking to see if the UDF is blank before doing a calculation.