Diary an action after a number of working days

Solved a problem in an elegant manner and want to show off your code? Know a hard-to-find feature? Post it here for the benefit of others. Questions don't belong here.
Post Reply
steve
Posts: 375
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 75 times

Diary an action after a number of working days

Post by steve » Tue Jun 02, 2015 3:14 pm

This code will diary an email to be sent to the client after a certain number of WORKING DAYS.

In this example, we exclude weekends

You could extend the code to account for public holidays. The RTA Low Value code uses a similar process you may wish to examine.

Code: Select all

QUESTION( "After how many working days do you want to send the client satisfaction survey?" , "number" ) 
v-working-days = return-value 
#initialise counter for how many working days have passed so far in our loop
v-found = 0 
#initialise couter for loop. The value of this counter will be the number of CALENDAR days that correspond to the number
#of working days requested
v-loop = 0 
#iterate over a loop until we have counted the required number of working days
WHILE v-found < v-working-days DO 
    #advance the counter 
    v-loop = v-loop +1 
    #what is the date in v-loop days time?
    v-date-to-test = DATE-FROM-TODAY( v-loop ) 
    #work out what day of the week this date is
    dayofweek = WEEKDAY( v-date-to-test ) 
    IF dayofweek = "Saturday" OR dayofweek = "Sunday" THEN 
        #  weekends don't count towards working days
    ELSE 
    # this is a working day - add one to our counter for how many working days we have found
        v-found = v-found + 1 
    END 
END 
#v-loop has counted how many calendar days are needed to give the required number of working days
# now send email for v-loop days time 
DIARY AN ACTION AFTER (v-loop) DAYS (SEND-E-MAIL) WITH TEMPLATE (CL123) DIARY TO (CLIENT) DIARY AT (MAIN) DIARY DETAIL (Client Satisfaction Survey) DIARY FOR (Current Case Handler) CATEGORY (0) CASE ( CURRENT-CASE )

Post Reply