[rt-users] Filling Dates fields with scrip
Schultz, Eric
ESchultz at corp.untd.com
Thu Feb 9 11:40:37 EST 2006
Not sure if this will help, but this was from a scrip in my test RT database (for the customcommitcode):
# ------------------------------------------------------------------- #
my $date = RT::Date->new($RT::SystemUser);
$date->SetToNow;
if ($self->TicketObj->StartsObj->AsString eq "Not set") {
$self->TicketObj->SetStarts($date->ISO);
}
if ($self->TicketObj->DueObj->AsString eq "Not set") {
$date->AddDays($RT::OverdueAfter);
use Business::Hours;
my $bizhours = new Business::Hours;
if ($RT::BusinessHours) {
$bizhours->business_hours(%$RT::BusinessHours);
}
my $due = $bizhours->first_after($date->Unix);
$date->Set(Format => 'unix', Value => $due);
$self->TicketObj->SetDue($date->ISO);
}
return 1;
# ------------------------------------------------------------------- #
I believe that shows you how to "properly" check if one of the date portions of the ticket object is set.
________________________________
From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Schultz, Eric
Sent: Thursday, February 09, 2006 8:26 AM
To: Cristiano da Costa
Cc: rt-users at lists.bestpractical.com
Subject: RE: [rt-users] Filling Dates fields with scrip
What doesn't work about it? It doesn't reset the date? It always resets the date even if information was already filled out?
________________________________
From: Cristiano da Costa [mailto:crsurf at gmail.com]
Sent: Thursday, February 09, 2006 5:33 AM
To: Schultz, Eric
Cc: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Filling Dates fields with scrip
Hello Eric
I want to set a different SLA if user filled the field Start, bellow is my code, but doesn´t work.
Can you give me some tip?
my $now = RT::Date->new($RT::SystemUser);
my $sla = RT::Date->new($RT::SystemUser);
$now->SetToNow;
$sla->SetToNow;
$sla->AddSeconds(+14400);
if ( $self->TicketObj->Starts eq '1970-01-01 00:00:00' ) {
$self->TicketObj->SetStarts( $now->ISO );
}
else {
$sla = $self->TicketObj->Starts;
$sla->AddSeconds(+14400);
}
if ( $self->TicketObj->Started eq '1970-01-01 00:00:00' ) {
$self->TicketObj->SetStarted( $now->ISO );
}
if ( $self->TicketObj->Due eq '1970-01-01 00:00:00' ) {
$self->TicketObj->SetDue( $sla->ISO );
}
return 1;
Sds
Cristiano
On 2/1/06, Schultz, Eric <ESchultz at corp.untd.com> wrote:
I don't think the dates will ever be 'undef'. Instead, check for a default date. I believe that date is '1970-01-01 00:00:00' in our system.
if ( $self->TicketObj->Started eq '1970-01-01 00:00:00' ) {
________________________________
From: rt-users-bounces at lists.bestpractical.com [mailto: rt-users-bounces at lists.bestpractical.com <mailto:rt-users-bounces at lists.bestpractical.com> ] On Behalf Of Cristiano da Costa
Sent: Wednesday, February 01, 2006 8:31 AM
To: rt-users at lists.bestpractical.com <mailto:rt-users at lists.bestpractical.com>
Subject: [rt-users] Filling Dates fields with scrip
Hello
I want to fill the fields Starts, Started and Due after ticket creation, for this I´m using the code bellow on custom action in "on create" condition
my $now = RT::Date->new($RT::SystemUser);
my $sla = RT::Date->new($RT::SystemUser);
$now->SetToNow;
$sla->SetToNow;
$sla->AddSeconds(+3600);
$self->TicketObj->SetStarts( $now->ISO );
$self->TicketObj->SetStarted( $now->ISO );
$self->TicketObj->SetDue( $sla->ISO );
return 1;
This works, but if user that create tickts already fill these fields I don´t want to overwrite the user information, I tryed the following code in place of the code above, but doesn´t work.
my $now = RT::Date->new($RT::SystemUser);
my $sla = RT::Date->new($RT::SystemUser);
$now->SetToNow;
$sla->SetToNow;
$sla->AddSeconds(+3600);
if ( $self->TicketObj->Starts == undef ){
$self->TicketObj->SetStarts( $now->ISO );
}
if ( $self->TicketObj->Started == undef ){
$self->TicketObj->SetStarted( $now->ISO );
}
if ( $self->TicketObj->Due == undef ){
$self->TicketObj->SetDue( $sla->ISO );
}
return 1;
How can I test if user already fill these fields?
Thanks
Cristiano
More information about the rt-users
mailing list