I have a weird issue on some code that does not fire right for the first time. I have a form where if there was a previous value was less than 2 days, it will then put that value in an OBSNOW and if it is over 2 days, then it does nothing. There are 10 questions and it works for 2 – 10 but 1 will always pull in the previous value no matter how long ago it was entered.
While running a trace route, it evaluates the previous value as NULL so it always think that it is less of the 2 day’s. I have two 10 question questionnaires and it does it on both of the first questions.
Here is the code that I am using:
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 1"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 1",OBSPREV("NDI 1")) ELSE "" ENDIF} – Doesn’t work
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 2"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 2",OBSPREV("NDI 2")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 3"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 3",OBSPREV("NDI 3")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 4"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 4",OBSPREV("NDI 4")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 5"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 5",OBSPREV("NDI 5")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 6"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 6",OBSPREV("NDI 6")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 7"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 7",OBSPREV("NDI 7")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 8"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 8",OBSPREV("NDI 8")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 9"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 9",OBSPREV("NDI 9")) ELSE "" ENDIF}
{IF DURATIONDAYS(LAST_SIGNED_OBS_DATE("NDI 10"),str(._TODAYSDATE)) < "2" THEN OBSNOW("NDI 10",OBSPREV("NDI 10")) ELSE "" ENDIF}
Anyone see something similar to this?
I have run into issues when using DURATIONDAYS in my forms, and the culprit is usually a null value. The best practice I have developed is to always check that my data is not empty before running the DURATIONDAYS code.
Here is what I would do to the code you have above:
{IF LAST_SIGNED_OBS_DATE(“NDI 1″) <> "" THEN (IF DURATIONDAYS(LAST_SIGNED_OBS_DATE(“NDI 1″),str(._TODAYSDATE)) < “2″ THEN OBSNOW(“NDI 1″,OBSPREV(“NDI 1″)) ELSE “” ENDIF) ELSE "" ENDIF}
Even if your Obsterm does not have a NULL Value, the code may be running before the data from the OBS term is called, and it acts as a NULL, which is then evaluating as TRUE.
Let me know if you have any questions. Good Luck!
Daniel C.
I don't believe you need the quotes around 2.
I think the issue with your code may be the fact that DURATIONDAYS() does not return a number, it returns a string of a number (a character rather than a mathematical value). You are using the < operator to compare two strings in your code which can give some results that are not always what you generally want. You may find that if you use the val function it will work.
IF val(DURATIONDAYS(LAST_SIGNED_OBS_DATE(“NDI 2″),str(._TODAYSDATE)) )< 2 THEN OBSNOW(“NDI 2″,OBSPREV(“NDI 2″)) ELSE “” ENDIF}
(note that you also need to get rid of the quotes around the 2 so it is treated like a numerical value and not like a string)
Hope that helps.
-JWR