Copy link to clipboard
Copied
Hi all
If the form field is empty this code sets the variable nxtstep depending on the day of the week checking if the form field "is not date" and works fine in this case.
If the form field is not empty then it sets the variable nxtstep as the date that is selected which it does, however, it is not checking to see if it is a holiday. It should trigger the listfind function and check to see if the entered date is a holiday but it is just entering the date without going through this check.
Why is this not working? Thank you
<!--- UPDATE QUERY --->
<cfif isDefined("form.UPDATEADDBTN")>
<cfif FORM.ENTID GTE 1>
<cfset isCOMPANYNull = iif(len(trim(form.COMPANY)) EQ 0, true, false)>
<cfset isCOMMENTSNull = iif(len(trim(form.COMMENTS)) EQ 0, true, false)>
<!--- SET DATE AS FORM FIELD --->
<cfset nxtstep = trim(form.ABUNDANCE)>
<!--- SET DATE IF NO DATE ENTERED --->
<cfif not isDate(nxtstep)>
<cfif DayOfWeek(Now()) eq 2>
<cfset nxtstep = dateAdd("d", 2, now())>
<cfelseif DayOfWeek(Now()) eq 3>
<cfset nxtstep = dateAdd("d", 2, now())>
<cfelseif DayOfWeek(Now()) eq 4>
<cfset nxtstep = dateAdd("d", 2, now())>
<cfelseif DayOfWeek(Now()) eq 5>
<cfset nxtstep = dateAdd("d", 4, now())>
<cfelseif DayOfWeek(Now()) eq 6>
<cfset nxtstep = dateAdd("d", 3, now())>
<cfelseif DayOfWeek(Now()) eq 7>
<cfset nxtstep = dateAdd("d", 2, now())>
<cfelseif DayOfWeek(Now()) eq 1>
<cfset nxtstep = dateAdd("d", 1, now())>
</cfif>
<!--- IF A DATE IS ENTERED CHECK TO SEE IF IT IS A HOLIDAY --->
<cfelse>
<!--- CHECK TO SEE IF ENTERED DATE IS A HOLIDAY AND ADD DAYS--->
<cfif ListFind(ValueList(hols.holiday), nxtstep)>
<cfif DayOfWeek(nxtstep) eq 2>
<cfset nxtstep = dateAdd("d", 2, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 3>
<cfset nxtstep = dateAdd("d", 5, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 4>
<cfset nxtstep = dateAdd("d", 2, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 5>
<cfset nxtstep = dateAdd("d", 4, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 6>
<cfset nxtstep = dateAdd("d", 6, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 7>
<cfset nxtstep = dateAdd("d", 2, nxtstep)>
<cfelseif DayOfWeek(nxtstep) eq 1>
<cfset nxtstep = dateAdd("d", 1, nxtstep)>
</cfif>
</cfif>
</cfif>
You are doing several things that might contribute to the problem. In your first block of code, you are using dateadd to set nxtstep to a datetime variable. In the next block of code, you are checking to see if this datetime variable appears in a list.
Since a list is just a delimited string, looking for datetime variables is bound to fail unless you convert those variables to a string. You can use dateformat for that. Choosing the correct format should also solve your other problem of your d
...Copy link to clipboard
Copied
You are doing several things that might contribute to the problem. In your first block of code, you are using dateadd to set nxtstep to a datetime variable. In the next block of code, you are checking to see if this datetime variable appears in a list.
Since a list is just a delimited string, looking for datetime variables is bound to fail unless you convert those variables to a string. You can use dateformat for that. Choosing the correct format should also solve your other problem of your datetime variables including a time portion while your list of holidays probably does not.
I vaguely remember similar questions from you. You should re-read the answers you got. You might be disregarding some of them.
Copy link to clipboard
Copied
Hi Dan
Thanks, the code that checks the list of holidays works fine when it is in a separate page on its own and I set the variable like this:
<cfset nxtstep = '2012-12-25'>
That's why I think the problem may be in the cfif statement? That aside where do I dateformat the variable, here?
<cfset nxtstep = trim(form.ABUNDANCE)>
So it would be?:
<cfset nxtstep= trim(DateFormat(form.ABUNDANCE, "yyyy-mm-dd"))>
Copy link to clipboard
Copied
What does form.abundance look like?