Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to trigger Listfind function

Guest
Jul 17, 2012 Jul 17, 2012

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>

791
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 17, 2012 Jul 17, 2012

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

...
Translate
LEGEND ,
Jul 17, 2012 Jul 17, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 17, 2012 Jul 17, 2012

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"))>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 18, 2012 Jul 18, 2012
LATEST

What does form.abundance look like?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources