Callback with no TicketObject arg, guidance needed

Using RT 4.2.3

Hi all,

This callback in share/html/Elements/EditCustomFields does not pass
$TicketObj (and it could, but was ommitted, perhaps on purpose?):

<%INIT>
...
$m->callback( %ARGS, CallbackName => 'MassageCustomFields',

CustomFields => $CustomFields );

</%INIT>

In my MassageCustomFields callback code (per above), I am trying to
determine if a certain CF has a value of /no/i

Given the arguments available to me in the callback, I am not sure how
to do that. All of my work in the past has involved method calls on
$TicketObj.

Debug-printing the contents of %ARGS from inside the MassageCustomFields
callback, I see that ARGS{‘Object’} = 'RT::Ticket=HASH(0x7f0b5b540db8)

Just use that as my $TicketObj? Is that sane/safe?

Additionally, if my intention is to ultimately use MassageCustomFields
to modify $CustomFields, isn’t that going to fail due to the callback
not being passed a hash reference ?

This callback in share/html/Elements/EditCustomFields does not pass
$TicketObj (and it could, but was ommitted, perhaps on purpose?):

<%INIT>
...
$m->callback( %ARGS, CallbackName => 'MassageCustomFields',

CustomFields => $CustomFields );

</%INIT>

In my MassageCustomFields callback code (per above), I am trying to
determine if a certain CF has a value of /no/i

Given the arguments available to me in the callback, I am not sure how
to do that. All of my work in the past has involved method calls on
$TicketObj.

Debug-printing the contents of %ARGS from inside the MassageCustomFields
callback, I see that ARGS{‘Object’} = 'RT::Ticket=HASH(0x7f0b5b540db8)

Just use that as my $TicketObj? Is that sane/safe?

Yes – ish. Note that custom fields can exist on things that aren’t
tickets, and Elements/EditCustomFields is also used for them. All
that’s promised is that $Object ISA RT::Record, so you should check
$Object->isa(“RT::Ticket”) before you carry on.

Additionally, if my intention is to ultimately use MassageCustomFields
to modify $CustomFields, isn’t that going to fail due to the callback
not being passed a hash reference ?

$CustomFields is an object (which are references). So if you modify the
object (by calling ->Limit on it, for instance) those changes are
preserved in the calling site. You can’t say $CustomFields =
RT::CustomFields->new(…), but you can $CustomFields->CleanSlate and
then re-add arbitrary limits.

  • Alex

Yes – ish. Note that custom fields can exist on things that aren’t
tickets, and Elements/EditCustomFields is also used for them. All
that’s promised is that $Object ISA RT::Record, so you should check
$Object->isa(“RT::Ticket”) before you carry on.

Thanks!

Follow-up question if I may:

How might I exclude fields X, Y, Z from $CustomFields in my callback?

I saw in RT-Extension-MandatoryOnTransition some code for INcluding some
named fields with ‘Limit’.

I’m not familiar with Limit (and hopefully its friends).

Should I just perldoc these files where 'sub Limit ’ is found and start
digging around for comprehension?

./lib/RT/Articles.pm
./lib/RT/CustomFieldValues/External.pm
./lib/RT/Tickets.pm
./lib/RT/Links.pm
./lib/RT/Queues.pm
./lib/RT/Users.pm
./lib/RT/SearchBuilder.pm

Follow-up question if I may:

How might I exclude fields X, Y, Z from $CustomFields in my callback?

Repeat for each name to exclude:

$CustomFields->Limit(
FIELD => ‘Name’,
OPERATOR => ‘!=’,
VALUE => ‘SomeNameToExclude’,
ENTRYAGGREGATOR => ‘AND’,
);

I’m not familiar with Limit (and hopefully its friends).

Should I just perldoc these files where 'sub Limit ’ is found and start
digging around for comprehension?

Limit comes from DBIx::SearchBuilder -

  • Alex

Alex, thanks again. I promise to write up what I’ve learned in the last
week (wiki).

I’ve hit another wall. While I can prove that the callback I am using is
in the right spot and is called…

The following Limit() IS working for Modify.html hits
(EditCustomFields). That is, hide certain fields for editing when a
control flag (CF) is set a certain way.

The following Limit() is NOT working for Display.html
(ShowCustomFields) hits. That is, hide certain fields from display when
a control flag (CF) is set a certain way. The problem is, they are still
showing when the control flag is set to not show them.

The code in both callback files is the same.

How might I exclude fields X, Y, Z from $CustomFields in my callback?

Repeat for each name to exclude:

$CustomFields->Limit(
FIELD => ‘Name’,
OPERATOR => ‘!=’,
VALUE => ‘SomeNameToExclude’,
ENTRYAGGREGATOR => ‘AND’,
);

Here is local/html/Elements/ShowCustomFields/MassageCustomFields (right
spot?) with comments relevant here:

<%args>
$CustomFields => undef
$ARGS => undef
$Object => undef
</%args>

<%init>

NOTE: If I enable these 4 short-circuit lines, Display.html does

in fact only show the ‘Scope’ custom field as a control/test.

So a) the callback location seems correct and b) it proves we can

at least control the contents of $CustomFields.

$CustomFields->Limit(FIELD => ‘Name’, OPERATOR => ‘=’,

VALUE => ‘Scope’, ENTRYAGGREGATOR => ‘AND’,

CASESENSITIVE => 0);

return;

my $ticket = $ARGS{‘Object’};

The fields to hide unless ‘Noteworthy = Yes’

my @childfields = (“Details”, “Response”, “Total emails”);

Default to showing all fields in @childfields

my $showchildren = 1;

Determine whether to show child fields or not

while (my $cf = $CustomFields->Next) {
my $nam = $cf->Name;
my $val = $ticket->FirstCustomFieldValue($nam);
if ($nam =~ /^noteworthy$/i and $val !~ /^yes$/i) {
$showchildren = 0;
last;
}
}

if (! $showchildren) {
# In theory, this should exclude all fields in @childfields
$CustomFields->Limit(FIELD => ‘Name’, OPERATOR => ‘!=’, VALUE =>
‘$_’, ENTRYAGGREGATOR => ‘AND’, CASESENSITIVE => 0) for (@childfields);
}
</%init>
%# EOF

if (! $showchildren) {
# In theory, this should exclude all fields in @childfields
$CustomFields->Limit(FIELD => ‘Name’, OPERATOR => ‘!=’, VALUE =>
‘$_’, ENTRYAGGREGATOR => ‘AND’, CASESENSITIVE => 0) for (@childfields);
}

Perl only interpolates variables in double quotes, not single quotes.
You want « VALUE => "$" »
or « VALUE => $
»
not « VALUE => ‘$_’ »

  • Alex