Hi,
I have made a “datetime” CustomField. Whenever a ticket is changed from open
to resolve the date and time will be inserted into the custom field.
However I want it to display the time elapsed e.g. 40 minutes ago etc.
This is the code I am using in location
/html/Callbacks/MyRT/Elements/RT__Ticket/ColumnMap
<%init>
$COLUMN_MAP->{DifferenceReopenedTime} = {
title => ‘Reopened’, # loc
attribute => ‘Reopened’,
value => sub {
my $CFValue = $Ticket->FirstCustomFieldValue(‘13’)
my $now = RT::Date->new($RT::SystemUser);
$now->SetToNow();
return $CFValue->AgeAsString();
}
};
</%init>
<%args>
$COLUMN_MAP
</%args>
Can anyone help
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100.html
RT automatically stores dates and times into tickets when they are created,
opened and closed.
I notice that you want a relative value (e.g. “40 minutes ago”), which
means that that value is only meaningful for a very short time, so perhaps
you’re wanting to place it in an outgoing email or something.
Can you tell us more about how you want to use this? I suspect so far that
a custom field isn’t necessary.On 31/07/2014 1:29 am, “AJ” aaron.mccarthy@southwestern.ie wrote:
Hi,
I have made a “datetime” CustomField. Whenever a ticket is changed from
open
to resolve the date and time will be inserted into the custom field.
However I want it to display the time elapsed e.g. 40 minutes ago etc.
This is the code I am using in location
/html/Callbacks/MyRT/Elements/RT__Ticket/ColumnMap
<%init>
$COLUMN_MAP->{DifferenceReopenedTime} = {
title => ‘Reopened’, # loc
attribute => ‘Reopened’,
value => sub {
my $CFValue = $Ticket->FirstCustomFieldValue(‘13’)
my $now = RT::Date->new($RT::SystemUser);
$now->SetToNow();
return $CFValue->AgeAsString();
}
};
</%init>
<%args>
$COLUMN_MAP
</%args>
Can anyone help
RT Training - Boston, September 9-10
Training — Best Practical Solutions
I’m just using the custom field at the moment to store the date and time of
which a ticket was re opened. I was using this custom field value in the
file I mentioned in the first message along with code I’m using also. I’m
starting to suspect I do not need a custom field. See image of what I have
so far. Is there another way about using this?
http://requesttracker.8502.n7.nabble.com/file/n58112/untitled.bmp
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58112.html
Okay, I understand now: you want to track when a ticket moves from resolved
to open (which isn’t recorded automatically), not open to resolved (which
is).
- You need to obtain access to the ticket here via shift, not $Ticket.
- One line is missing a terminating semicolon.
- You can use names when loading custom field values (I’m guessing 13 is
the ID), but ID works too.
- The date object needs to be loaded with the time of the field, not the
current time.
- The AgeAsString method is provided by the RT::Date object, not the
ticket.
This code is untested but should be closer to what you want, although it
may need to be tweaked depending on the format in which you write the
custom field value beforehand:
…
value => sub {
my $ticket = shift;
my $reopened = $ticket->FirstCustomFieldValue(13);
my $date = RT::Date->new($RT::SystemUser);
$date->Set( Format => ‘ISO’, Value => $reopened );
return $date->AgeAsString;
}
…On 31 July 2014 16:53, AJ aaron.mccarthy@southwestern.ie wrote:
I’m just using the custom field at the moment to store the date and time of
which a ticket was re opened. I was using this custom field value in the
file I mentioned in the first message along with code I’m using also. I’m
starting to suspect I do not need a custom field. See image of what I have
so far. Is there another way about using this?
http://requesttracker.8502.n7.nabble.com/file/n58112/untitled.bmp
RT Training - Boston, September 9-10
Training — Best Practical Solutions
Hi Alex, Thank you for all your help. I really appreciate it.
I used that bit of code, It didn’t have to be tweaked (I don’t think) as I
used the ISO format for my custom field. However, it does not seem to work.
I can’t seem to see where I am going wrong.
The CustomField is storing the correct datetime. In the search result. Am I
missing something?
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58121.html
That code seems okay to me. Is you anything useful being reported to RT’s
debug log?
Replacing all of that code with:
…
value => sub {
return ‘this works’;
},
…
could be useful in determining whether the problem lies with that code, or
elsewhere (i.e. how the search result column is being defined and used).
Hi Alex, Thank you for all your help. I really appreciate it.
I used that bit of code, It didn’t have to be tweaked (I don’t think) as I
used the ISO format for my custom field. However, it does not seem to work.
I can’t seem to see where I am going wrong.
The CustomField is storing the correct datetime. In the search result. Am I
missing something?
View this message in context:
http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58121.html
RT Training - Boston, September 9-10
This is the debug for my scrip which stores the datetime value for the custom
field.
http://requesttracker.8502.n7.nabble.com/file/n58123/Logs.bmp
As you can see, It is storing the date fine.
I did as you said and inserted This works into the sub content. Nothing
happened. Didn’t see it show up anywhere
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58123.html
If you don’t see “this works” in your search results with that change, then
I’d suspect a problem in how the new column is defined overall.
What’s the complete content of the file you’re using to define that new
search result column, where are you placing it, and what does your test
search result format look like as shown in the Advanced screen of the
search builder?On 01/08/2014 12:12 am, “AJ” aaron.mccarthy@southwestern.ie wrote:
This is the debug for my scrip which stores the datetime value for the
custom
field.
http://requesttracker.8502.n7.nabble.com/file/n58123/Logs.bmp
As you can see, It is storing the date fine.
I did as you said and inserted This works into the sub content. Nothing
happened. Didn’t see it show up anywhere
RT Training - Boston, September 9-10
Training — Best Practical Solutions
Advanced Search:
Query: Queue = ‘Helpdesk’ AND ( Status = ‘new’ OR Status = ‘open’ )
Format: ’ * id <WebPath/Ticket/Display.html?id=id>
/TITLE:#',
’ Subject <WebPath/Ticket/Display.html?id=id>
*/TITLE:Subject’,
‘Status’,
‘QueueName’,
‘OwnerName’,
‘Priority’,
‘NEWLINE’,
‘’,
‘Requestors’,
‘CreatedRelative’,
‘ToldRelative’,
‘LastUpdatedRelative’,
‘DifferenceReopenedTime’
I have put the new search in
/html/Callbacks/MyRT/Search/Elements/BuildFormatString/
and placed in a file called Default
In this file is:
<%INIT>
push @{$Fields}, ‘DifferenceReopenedTime’;
</%INIT>
<%ARGS>
$Fields => undef
</%ARGS>
I hope this helps
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58130.html
The search result format string from the Advanced screen of the search
builder looks okay to me.
The file you’ve referenced only manages the addition of the field to the
select box on the search builder screen, and is presumably in the correct
location and working if your new field is showing up in the select box.
What’s the full path to the file with the “it works” line, and that file’s
complete content?On 01/08/2014 1:44 am, “AJ” aaron.mccarthy@southwestern.ie wrote:
Advanced Search:
Query: Queue = ‘Helpdesk’ AND ( Status = ‘new’ OR Status = ‘open’ )
Format: ’ * id <WebPath/Ticket/Display.html?id=id>
/TITLE:#',
’ Subject <WebPath/Ticket/Display.html?id=id>
*/TITLE:Subject’,
‘Status’,
‘QueueName’,
‘OwnerName’,
‘Priority’,
‘NEWLINE’,
‘’,
‘Requestors’,
‘CreatedRelative’,
‘ToldRelative’,
‘LastUpdatedRelative’,
‘DifferenceReopenedTime’
I have put the new search in
/html/Callbacks/MyRT/Search/Elements/BuildFormatString/
and placed in a file called Default
In this file is:
<%INIT>
push @{$Fields}, ‘DifferenceReopenedTime’;
</%INIT>
<%ARGS>
$Fields => undef
</%ARGS>
I hope this helps
RT Training - Boston, September 9-10
Training — Best Practical Solutions
Hi Alex,
The location path is /html/Callbacks/MyRT/Elements/RT__Ticket/ColumnMap/Once
In the “Once” file I have contains this:
<%init>
$COLUMN_MAP->{DifferenceReopenedTime} = {
title => ‘Reopened’, # loc
attribute => ‘Reopened’,
value => sub {
return ‘THIS WORKS’;
}
};
</%init>
<%args>
$COLUMN_MAP
</%args>
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58141.html
I believe that you need to use “Reopened” in your search and the
BuildFormatString/Default callback, not “DifferenceReopenedTime” as you
currently have.
$RT_ROOT/local/html/Callbacks/MyRT/Search/Elements/BuildFormatString/Default
<%INIT>
push @{$Fields}, ‘Reopened’;
</%INIT>
<%ARGS>
$Fields => undef
</%ARGS>On 1 August 2014 17:55, AJ aaron.mccarthy@southwestern.ie wrote:
Hi Alex,
The location path is
/html/Callbacks/MyRT/Elements/RT__Ticket/ColumnMap/Once
In the “Once” file I have contains this:
<%init>
$COLUMN_MAP->{DifferenceReopenedTime} = {
title => ‘Reopened’, # loc
attribute => ‘Reopened’,
value => sub {
return ‘THIS WORKS’;
}
};
</%init>
<%args>
$COLUMN_MAP
</%args>
RT Training - Boston, September 9-10
Training — Best Practical Solutions
Hi Alex,
I made that change, restarted apache and cleared the cache on my browser but
still nothing after several attempts. Its like its not calling my column map
or something.
The name of the field stayed as “Difference Reopened Time” in my search. I
thought that it should have changed to “Reopened”. I tried looking for a
field called reopen however, there was none.
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58143.html
Be sure to clear the server-based Mason cache before restarting the web
server:
http://requesttracker.wikia.com/wiki/CleanMasonCache
as your changes to those files otherwise won’t be visible to RT.On 1 August 2014 19:27, AJ aaron.mccarthy@southwestern.ie wrote:
Hi Alex,
I made that change, restarted apache and cleared the cache on my browser
but
still nothing after several attempts. Its like its not calling my column
map
or something.
The name of the field stayed as “Difference Reopened Time” in my search. I
thought that it should have changed to “Reopened”. I tried looking for a
field called reopen however, there was none.
RT Training - Boston, September 9-10
Training — Best Practical Solutions
I cleared the mason cache, and sure enough ‘This works’ was displaying. So I
re entered the code you gave me and cleared the mason cache again. However,
‘This works’ is still displaying. So would the problem be with the code?
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58145.html
I suspect that maybe you haven’t restarted the web server after clearing
the Mason cache. Give that a shot; if no luck, errors should be making
their way to the log.On 1 August 2014 19:58, AJ aaron.mccarthy@southwestern.ie wrote:
I cleared the mason cache, and sure enough ‘This works’ was displaying. So
I
re entered the code you gave me and cleared the mason cache again. However,
‘This works’ is still displaying. So would the problem be with the code?
RT Training - Boston, September 9-10
Training — Best Practical Solutions
IT WORKS!!!
You were exactly right in regards to restarting apache.
Thanks for everything Alex.
Life saver.
Aaron
View this message in context: http://requesttracker.8502.n7.nabble.com/Add-Time-difference-in-search-result-tp58100p58147.html