Notifications during Task Life Cycle

In most common situations we might across the requirement to have different types of notifications during the life cycle of task.
Example : 1) Trigger Notifications on 30%,70% & 110% of task duration. to stating that task is waiting for accomplish the business needs.
Well that’s it. and we may think to use attached timers around task to get it down, fire on specific due dates on each timers… initially its look so rude to have three attached timers on a task. is in it?

lets begin to analyze it clearly.

"DUE IN" is priority setting for a user task, defines when task will be expected to complete.
based on this value and calculate the TWDate based on 30%, 70% & 110% duration of task.

Well one interesting scenario is to calculate TWDate excluding holidays, Yes count on only business days :).

We will talk about how to do it in another posts. lets assume we done calculation of three specific dates, Lets proceed with the implementation.

You may be interested in one of JS api – tw.system.rescheduleTimer(timerId, time)

Yep, you can reschedule timer by calling this api, passing parameters are timer id and TWDate.

Initialize the flag as shown in figure to capture or track the values of 30%, 70% and 110%. Most probably on Pre-Assignment’s of user task. lets say tw.local.flag = “30”;
pull one timer and attached on user task. and define the timer Id tw.local.timerId = tw.system.step.timer.id; set the custom date on timer, obviously it was calculated 30% due date.
Set the flag script as shown below.
its bit tricky to have set the flag like this, the main intention is. initially we already set the date in a timer for 30%, as per the cycle notification send for 30%task duration again  its set to 70% custom date notification and vice versa by using js api as shown in code

if(tw.local.notifAFPFlag=="30"){
tw.local.notifAFPFlag="70"
}else if(tw.local.notifAFPFlag=="70"){
tw.local.notifAFPFlag="110"
}else if(tw.local.notifAFPFlag=="110"){
tw.local.notifAFPFlag=""
}else{
tw.local.notifAFPFlag="NA";
}

reScheduleForReminders(Number(tw.epv.SLAConstants.DUE_DATE_VALIDATION_FORM),tw.local.timerAFPId,tw.local.notifAFPFlag);

JS function look like in below code.

function reScheduleForReminders(taskDueInHours,timerId,flag){
//var taskDueInHours = taskDueInHours;
if(flag == "30"){
log.info("###--------------->Welcome to 30% task duration<------------###"); var thirtyPercentInHours = Math.ceil(taskDueInHours/100 * 30); log.info("thirtyPercentInHours---->"+thirtyPercentInHours);
var thirtyPercentDate = calcuateBusinessDate(tw.env.TIME_SCHEDULE_NAME,new TWDate(),thirtyPercentInHours,"Hour")
log.info("thirtyPercentDate---->"+thirtyPercentDate);
tw.system.rescheduleTimer(timerId, thirtyPercentDate);
}else if(flag == "70"){
log.info("###--------------->Welcome to 70% task duration<------------###"); var seventyPercentInHours = Math.ceil(taskDueInHours/100 * 70); log.info("seventyPercentInHours---->"+seventyPercentInHours);
var seventyPercentDate = calcuateBusinessDate(tw.env.TIME_SCHEDULE_NAME,new TWDate(),seventyPercentInHours,"Hour")
log.info("seventyPercentDate---->"+seventyPercentDate);
tw.system.rescheduleTimer(timerId, seventyPercentDate);
}else if(flag == "110"){
log.info("###--------------->Welcome to 110% task duration<------------###"); var hundredTenPercentInHours = Math.ceil(taskDueInHours/100 * 110); log.info("hundredTenPercentInHours---->"+hundredTenPercentInHours);
var hundredTenPercentDate = calcuateBusinessDate(tw.env.TIME_SCHEDULE_NAME,new TWDate(),hundredTenPercentInHours,"Hour")
log.info("hundredTenPercentDate---->"+hundredTenPercentDate);
tw.system.rescheduleTimer(timerId, hundredTenPercentDate);
} else{
log.info("###--------------->Welcome Infinite Loop<------------###"); var date=new tw.object.Date(); date.parse("12/31/2099","MM/dd/yyyy"); log.info("reschedule to infinite--date-->"+date);
tw.system.rescheduleTimer(timerId, date);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *