Scrip help needed on date formatting

To all,

I'm a newbie to perl. I've written a few simple scrips and they are 

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

I get nothing. If I change the value of $cf_value to simply 

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL

Hi,
Can you give some info about the CF you are using?
What is the type and validation settings on it?

-AshishFrom: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL

http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Hey Ken,
localize the variables as follows and try it out :

my ( undef, undef, undef, $day, $mon, $year ) = localtime( time );
my $cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

-AshishFrom: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL

http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Ashish,

Just "Enter one value". That's it. No validation settings. Although 

I’ve thought about using "(?#Date
yyyy/mm/dd)^(([1-2][0-9][0-9][0-9])/(0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1]))?$"
as a validation setting.

Kenn
LBNLOn 3/3/2009 11:21 AM, Potla, Ashish Bassaliel wrote:

Hi,
Can you give some info about the CF you are using?
What is the type and validation settings on it?

-Ashish


From: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Ashish,

Tried that. No joy.

Kenn
LBNLOn 3/3/2009 11:40 AM, Potla, Ashish Bassaliel wrote:

Hey Ken,
localize the variables as follows and try it out :

my ( undef, undef, undef, $day, $mon, $year ) = localtime( time );
my $cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

-Ashish


From: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Well, it worked for me!
Sorry… keep tweaking it.

hope you have return 1; in the cleanup code as well.
-AshishFrom: Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 1:50 AM
To: Potla, Ashish Bassaliel
Cc: rt Users
Subject: Re: [rt-users] Scrip help needed on date formatting

Ashish,

    Tried that. No joy.

Kenn
LBNL

Ashish,

Yep.

KennOn 3/3/2009 12:21 PM, Potla, Ashish Bassaliel wrote:

Well, it worked for me!
Sorry… keep tweaking it.

hope you have return 1; in the cleanup code as well.
-Ashish


From: Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 1:50 AM
To: Potla, Ashish Bassaliel
Cc: rt Users
Subject: Re: [rt-users] Scrip help needed on date formatting

Ashish,

    Tried that. No joy.

Kenn
LBNL

On 3/3/2009 11:40 AM, Potla, Ashish Bassaliel wrote:

Hey Ken,
localize the variables as follows and try it out :

my ( undef, undef, undef, $day, $mon, $year ) = localtime( time );
my $cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

-Ashish


From: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Ashish,

Sorry. I'm such a dummy. I made your changes and when I tested it, I 

forgot to change a condition back to original (I was testing some other
stuff). It now works, like you said it would. It was the missing “my”.
THANKS!!

Kenn
LBNLOn 3/3/2009 12:21 PM, Potla, Ashish Bassaliel wrote:

Well, it worked for me!
Sorry… keep tweaking it.

hope you have return 1; in the cleanup code as well.
-Ashish


From: Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 1:50 AM
To: Potla, Ashish Bassaliel
Cc: rt Users
Subject: Re: [rt-users] Scrip help needed on date formatting

Ashish,

    Tried that. No joy.

Kenn
LBNL

On 3/3/2009 11:40 AM, Potla, Ashish Bassaliel wrote:

Hey Ken,
localize the variables as follows and try it out :

my ( undef, undef, undef, $day, $mon, $year ) = localtime( time );
my $cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

-Ashish


From: rt-users-bounces@lists.bestpractical.com [rt-users-bounces@lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker@lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting

To all,

    I'm a newbie to perl. I've written a few simple scrips and they are

working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it’s status changed to ‘stalled’, I want to
update a Custom Field with the yyyy/mm/dd format for today’s date. The
code I was given for this is as follows:

Custom Action Prep Code:

set the CF Work-Completed Date

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Stalled Date”;
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

    I get nothing. If I change the value of $cf_value to simply

(localtime), I get the full-fledged format of “Thu Feb 26 14:54:33 2009”.
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?

Kenn
LBNL


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com