Implementing Scrip to take Date from Custom Field and Set Due

I am experimenting with taking an ISO style date (2024-05-14) that’s being added as a custom field value (from a custom web form that’s emailed in to RT - I already got the front-end working and RT to extract the custom field and put it into a ticket CF by way of a batch scrip “On Create” that extracts the CF from a SMTP header from my web form and successfully adds into a CF).

Then I have a new scrip I’m playing with that I can’t get to work… I’ve tried it as a normal and a batch scrip, but I think since the CF is being populated from a previous batch scrip on create, the next scrip will have to be batch also.

The new scrip is also a batch scrip:

Condition “User Defined”
Action: “User Defined”

Custom condition -

return 0 unless $self->TransactionObj->Type eq “Create”;
return 0 unless $self ->TicketObj->Subject =~ /New Hire/ ;
return 1;

Custom action preparation code:
return 1;

Custom action commit code (I’ve tried (3) different action commit code’s):

Try1 -

my $ticket = $self->TicketObj;
my $CFName = “Start Date”;
my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new ($QueueObj->CurrentUser);
$CFObj->LoadByNameAndQueue(Name=>$CFName, Queue=>$QueueObj->id);
startdate = $self->TicketObj->FirstCustomFieldValue($CFObj->id);
$self->TicketObj->SetDue($startdate->ISO);

Try2 -

my $ticket = $self->TicketObj;
my $CFName = “Start Date”;
my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new ($QueueObj->CurrentUser);
$CFObj->LoadByNameAndQueue(Name=>$CFName, Queue=>$QueueObj->id);
my $Due = new RT::Date($RT::SystemUser);
$Due = $self->TicketObj->FirstCustomFieldValue($CFObj->id);
$Due->AddDays(1);
$self->TicketObj->SetDue($Due->ISO);

Try3 -

my $ticket = $self->TicketObj;
my $CFName = “Start Date”;
my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new ($QueueObj->CurrentUser);
$CFObj->LoadByNameAndQueue(Name=>$CFName, Queue=>$QueueObj->id);
my $startdate = $self->TicketObj->FirstCustomFieldValue($CFObj->id);
$self->TicketObj->SetDue($startdate->ISO);

Any chance anyone can give the above a quick once-over? I feel like I’m missing something really obvious here…

How about something like:

my($ret,$msg) = $self->TicketObj->SetDue(
    $self->TicketObj->CustomFieldValuesAsString("Start Date") . ' 00:00:00'
  );

Thank you Jim :slight_smile: That did it! by adding " 00:00:00" that did the trick in terms of getting the field to populate…

… Except that it applied UTC to the Due field… I see the value of ‘2024-05-20’ in the CF, except when Due is set it shows up as “Due: Thu May 19 20:00:00 2024”, which is interestingly enough 4 hours behind instead of 4 hours ahead (if it were actually UTC).

I have my RT instance configured to:

Set( $Timezone, 'US/Eastern');

and everywhere else in RT I see the time correctly displayed… It would appear that SetDue is somehow changing the timezone or at the very least subtracting 4 hours… I’ll dig into this on my end! Thanks again!

You might want to try passing in a full ISO date with timezone. Something like:

2024-05-20T20:00:00-04:00