https://rt-wiki.bestpractical.com/index.php?title=DueDateinBusinessHours&feed=atom&action=historyDueDateinBusinessHours - Revision history2024-03-29T04:53:04ZRevision history for this page on the wikiMediaWiki 1.37.2https://rt-wiki.bestpractical.com/index.php?title=DueDateinBusinessHours&diff=1030&oldid=prevAdmin: 3 revisions imported2016-04-06T20:08:52Z<p>3 revisions imported</p>
<p><b>New page</b></p><div>Description: set ticket to be due in a specified number of business hours (so that weekends and nights are excluded)<br />
<br />
Uses Jesse Vincent's Business::Hours library, available from CPAN<br />
<br />
Condition: On Ticket Creation<br />
Template: Global template: Blank<br />
Action: User Defined<br />
<br />
Custom Action Preparation Code: return 1;<br />
Custom Action Cleanup Code:<br />
<br />
my $duedate = RT::Date-&gt;new($RT::SystemUser);<br />
my $hoursuntildue = 4;<br />
use Business::Hours;<br />
my $hours = Business::Hours-&gt;new();<br />
my $curtime = time;<br />
my $bus_hours_duetime = $hours-&gt;add_seconds ($curtime, ($hoursuntildue*60*60));<br />
$duedate-&gt;Set(Format=&gt;'unix', Value=&gt;$bus_hours_duetime);<br />
$self-&gt;TicketObj-&gt;SetDue($duedate-&gt;ISO);<br />
return(1);<br />
<br />
This takes care of the case in which [[TimeLeft]] is modified after ticket creation:<br />
<br />
Description: Upon editing, convert TimeLeft into business days<br />
<br />
Condition: User Defined<br />
Action: User Defined<br />
Template: Global template: Blank<br />
Stage: TransactionCreate<br />
<br />
Custom Condition:<br />
if ($self-&gt;TransactionObj-&gt;Field eq 'TimeLeft') {<br />
return(1);<br />
} else {<br />
return(undef);<br />
}<br />
<br />
Custom Action Preparation Code: return 1;<br />
<br />
Custom action cleanup code:<br />
my $duedate = RT::Date-&gt;new($RT::SystemUser);<br />
my $hoursperday = 9;<br />
my $hoursuntildue = $self-&gt;TransactionObj-&gt;NewValue()*$hoursperday;<br />
use Business::Hours;<br />
my $hours = Business::Hours-&gt;new();<br />
my $curtime = time;<br />
my $bus_hours_duetime = $hours-&gt;add_seconds ($curtime, ($hoursuntildue*60*60));<br />
$duedate-&gt;Set(Format=&gt;'unix', Value=&gt;$bus_hours_duetime);<br />
$self-&gt;TicketObj-&gt;SetDue($duedate-&gt;ISO);<br />
return(1);</div>Admin