[rt-users] Callback with no TicketObject arg, guidance needed
Alex Vandiver
alexmv at bestpractical.com
Wed Mar 19 10:15:44 EDT 2014
On Tue, 2014-03-18 at 15:55 -0400, Jeff Blaine wrote:
> 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
More information about the rt-users
mailing list