Countdown from custom field

is it possible to create a countdown for the due date in a ticket, from a custom field (for example 8h or 6h) ?

I wouldn’t mind trying a script for this, i just want to see if it is possiable :slight_smile:

Thanks :slight_smile:

You could write a rt-crontool that runs every X minutes and updates some custom field. You’d just need to create a custom action for it to call that does the updating.

You can also add the search result column “DueRelative” to your saved searches and it will show the result like “5 hours ago” or “9 hours”.

1 Like

At the moment we are using rt-ticket 4.4.0, is this still possible?

Yes both options should be supported

1 Like

just found it on rt-crontool - RT 4.4.0 Documentation - Best Practical haha, thanks a million :slight_smile:

No problem, for creating your own RT::Action you can use an existing action as an example of the structure. Then you can put your file in “/opt/rt4/local/lib/Action/SetCountdown.pm”. It should be call-able from the crontool then

1 Like

Are you able to use all the functions inside
https://docs.bestpractical.com/rt/4.4.0/index.html
or only the Actions Section?

Sorry I don’t quite follow, DueRelative is a column map for search results. You could have that displayed for search results without wiring any code

1 Like

I saw you can use RT::Action, can you use RT::Condition, RT::CustomFields, etc ?
thanks :slight_smile:

I saw you can use RT::Action, can you use RT::Condition, RT::CustomFields, etc ?

For rt-crontool? You can use a condition, I believe there is at least on example in the docs. How would you use RT::CustomFields? Inside a custom action you can create a new RT::CustomFields collection if thats what you mean!

1 Like

The aim is to basically get a date, and add the hours from a custom field, along with some other calculations. im afraid it might not be possible using rt-crontool because I can not store values in a var for example. do you have some other suggestions how i can go about this?

thanks again :slight_smile:

I believe you can still use a crontool, I’d imagine it will look something like this:

 rt-crontool \
      --search RT::Search::FromSQL  --search-arg "Due IS NOT NULL AND 'CF.{Countdown}' LIKE ''" \
      --action RT::Action::SetCountdown

Then in the RT::Action, SetCountdown you can have some code run on each ticket found by the search and set the Countdown custom field to some value that you calculated.

1 Like

Starting to understand, thanks a million! :slight_smile:

Hi again :slight_smile:
By any chance does RT::Date use the perl DateTime package? (use DateTime;)

Thanks :slight_smile:

Yes, there’s a use DateTime; line near the top of /opt/rt5/lib/RT/Date.pm. There’s also a DateTimeObj method that will return a DateTime object from an RT::Date object.

1 Like

Perfect, thanks :slight_smile:
At the moment I am using RT 4.4.0, so I checked /lib/RT/Date.pm and saw that the default formatter is ISO.

So the idea is to add hours to the current time

		my $getCurrentTime = RT::Date->new( RT->DateTimeObj );
		my $DeadLine = $getCurrentTime -> add(hours => $getCustomFieldValue);