Solved

Help with repeating a record based on a date.

Posted on 2002-03-27
13
241 Views
Last Modified: 2013-12-24
Hi all,

I need help making an entry in my CF calendar program repeat.  

What I want to do is offer the customer the option of selecting an option in the add form that would repeat all the fields of the add form for Monday thru Friday of each week of the month.

I will be happy to provide my code so you may interegate, if needed.

Anyone have any ideas on how I can accomplish this?
0
Comment
Question by:g118481
  • 6
  • 6
13 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899850
like if repeat is checked.. then loop through M-F and add it to your calendar DB?

CJ
0
 
LVL 1

Author Comment

by:g118481
ID: 6899869
Yes.
I think the difficulty of this task is how to calculate the new date for each new record.

Now, I know I want the form fields to be exactly the same, however, I really don't know how to repricate each new record with the next date in the week.

Maybe it would be better if my new code would just repricate the remainder of the current week only.
(my reference to week applies to Monday - Friday only)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899895
Do you want it to repeat continuously (over next x weeks) or JUST the current week.
0
 
LVL 1

Author Comment

by:g118481
ID: 6899934
Would it be difficult for the code to repeat the selected event for one month at a time?

If not, then I would like that, else it shouldn't repeat for more than a single year at a time so the db doesn't grow too large at one time.  Also, there has to be some kind of limit, less the code goes into an infinite loop, right?

Thanks
0
 
LVL 1

Author Comment

by:g118481
ID: 6902530
Cheekycj,

any help you offer would be very much appreciated.
0
 
LVL 3

Expert Comment

by:winningl
ID: 6902694

Can you post some of your code?

I'm not sure what you want. Do you mean to loop through M to F and add the same form data into DB? What's the primary key in your table?

winningl
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 19

Expert Comment

by:cheekycj
ID: 6902785
winning! I think that is exactly what he wants.

sorta like:

<!--- Assuming VARIABLES.startDate is the start Date --->
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
     <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
     <cfloop index="d" from="2" to="6" step="1">
          <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
          <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
     </cfloop>
     <!--- Add 2 days for weekend --->
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6903216
Thanks for the update.

How would I implement your suggested code into my add/edit form listed below.

/**************************************************/
<CFSET FIELDLIST = "FuseCalendar_ID,CalendarDate,EventDescription,Location,Email,Website,EventName,Contact,Phone,ShowTime,FuseBox_ID">


<CFIF attributes.fuseaction IS "AddEvent">
      <!--- If adding a new event, this code is run, setting each form field to empty.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "")>
      </CFLOOP>
      <cfset time = "8:00 AM">
<CFELSEIF attributes.fuseaction IS "EditEventID">
      <!--- if the user is creating a editing a record --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
                  from event
                        where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <!--- I will now set the form field variables to the event to be edited based on the record taken from the query above.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      <cfset Time = "#TimeFormat(CalendarDate)#">
      
<CFELSEIF attributes.fuseaction IS "RemoveEventID">
      <!--- This code is similar to the editing of an event, but will just display the data that is about to be deleted. --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
            from event
            where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      
      <cfset Time = "#TimeFormat(CalendarDate)#">
</CFIF>
<blockquote></blockquote>
<html>
<head>
      <title>Alter the Event Data for the Calendar.</title>
</head>

<Body background="/release/bg_stripe.gif" rightmargin="2" leftmargin="2">

You are about to <cfif attributes.fuseaction is "AddEvent"><B>add</B> a new event to<cfelseif attributes.fuseaction is "EditEventID"><B>modify</B> an event on<cfelseif attributes.fuseaction is "RemoveEventID">remove an event on</CFIF> the Calendar.  Fill out the form below.  All fields in <FONT COLOR="#800000">red</FONT> are required.<p>

<FORM ACTION="index.cfm" METHOD="post">
      <INPUT Type="Hidden" Name="fuseaction" Value="<cfoutput>#attributes.fuseaction#Process</cfoutput>">
      
      <INPUT TYPE="HIDDEN" NAME="FuseCalendar_ID" value="<CFOUTPUT>#FuseCalendar_ID#</CFOUTPUT>">
      <TABLE border="0">

  <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Name:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="EventName" SIZE="20" MaxSize="100"<CFOUTPUT>value="#EventName#"</CFOUTPUT>>
                  </TD>
            </TR>
            
            <TR>
                <TD VALIGN="top"><FONT COLOR="800000"></FONT> </TD>

 <TR>
                <TD VALIGN="top"><FONT COLOR="#800000">Location:</FONT> </TD>
                <TD>
                         <INPUT TYPE="text" NAME="Location" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Location#"</CFOUTPUT>
                  </TD>
            </TR>

            <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Date:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="CalendarDate" SIZE="20" MaxSize="100"<CFOUTPUT>value="<cfif CalendarDate NEQ "">#DateFormat(CalendarDate)#<cfelse>#DateFormat(NOW())#</CFIF>"</CFOUTPUT>>
                        <input type="hidden" Name="CalendarDate_Date" Value="The Date must be in a valid format, such as 4/27/1998">
                  </TD>
            </TR>

            

             <TR>
                <TD VALIGN="top">Time:</TD>
                <TD>
                        Show? Yes <INPUT TYPE="Radio" NAME="ShowTime" VALUE="YES" <cfif ShowTime is "YES">CHECKED</CFIF>>
                        No <INPUT TYPE="Radio" NAME="ShowTime" VALUE="NO" <cfif ShowTime NEQ "YES">CHECKED</CFIF>> Time:
                        <INPUT TYPE="text" NAME="Time" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Time#"</CFOUTPUT>>
                  </TD>
            </TR>
                  
             <TR>
                <TD VALIGN="top">Contact Name:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Contact" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Contact#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Phone Number:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="phone" SIZE="20" MaxSize="50"<CFOUTPUT>value="#phone#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Email:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Email" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Email#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Web Site Address:</TD>
                <TD>
                        http://<INPUT TYPE="text" NAME="WebSite" SIZE="20" MaxSize="50"<CFOUTPUT>value="#WebSite#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Description:</FONT> </TD>
                <TD>
                        <TextArea NAME="EventDescription" Cols="45" ROWS="7" Wrap=Virtual><CFOUTPUT>#EventDescription#</CFOUTPUT></textarea>
                  </TD>
            </TR>
                              
      <tr>
            <td></TD>
            <td>
                  <input type="hidden" name="FuseBox_ID" Value="999">
                  <input type="hidden" name="EventDescription_required" Value="You must provide a description for your event.">
                  <input type="hidden" name="EventName_required" Value="You must provide a name for your event.">      
                  <!--- <input type="hidden" name="Location_required" Value="You must provide a location for your event."> --->
                  <input type="hidden" name="CalendarDate_required" Value="You must provide a description for your event.">
                  <INPUT TYPE="submit" VALUE="Make It Happen">
            </TD>
      </TR>

</FORM>
      </TABLE>
</body>
</html>
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6903229
that is your form page right.. what about the page that actually inserts the info into the DB?
0
 
LVL 1

Author Comment

by:g118481
ID: 6903475
Sorry,

I should have included my action page.  Here it is.
Thanks for your time!

/****************************************************/
<cftransaction>
     <cfmodule template="act_max_id.cfm"
          datasource="cmrmm"
          tablename="event"
          primarykey="FuseCalendar_id">
               
     <cfquery name="addToCalendar" datasource="cmrmm">
          Insert Into Event
          (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName, contact, phone, showtime)
               Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(attributes.CalendarDate)# #TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',  '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#', #attributes.showtime#)
     </CFQUERY>
</cftransaction>
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
ID: 6903530
is attributes.CalendarDate the startDate?

then it would be:

<!--- Assuming VARIABLES.startDate is the start Date --->
<cfset VARIABLES.startDate = attributes.CalendarDate>
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
    <cfloop index="d" from="2" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
         <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
    </cfloop>
    <!--- Add 2 days for weekend --->
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6910309
Cheekycj,

I have tested your code, and I am not getting the results I expected.

It is writing 25 records for April (the current month now), and all are exact duplicated of eachother, including the "startdate"

How can I change the code to add the next number of the day to the startdate field?

Thanks.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6918636
you used the above code exactly??

I am incrementing startDate which is what gets inserted.. you have to use the queries I have not the ones you have which use attributes.CalendarDate or replace it with VARIABLES.startDate.

CJ
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now