Solved

Help with repeating a record based on a date.

Posted on 2002-03-27
13
242 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

19 Experts available now in Live!

Get 1:1 Help Now