Help build a JSON request


#1

I’m trying to build a JSON request so that I can shoot info from RT to an external site.

I’m using a custom component to build and execute the request, and then also handle the response.

My challenge is that I am not able to get a custom field value, which I would like to add to the JSON request.

Within the component, I use this to capture the ticket object

my $TicketObj ||= LoadTicket($OriginalTicket);

All I would like to do is grab the value from a custom field on that ticket. When I try to use

my %category_open = CustomField->Load(4);

I get "Can’t locate object method “Load” via package “CustomField”… which doesn’t make sense to me, since that should already be included. I’m guessing on the syntax for using CustomField->Load as I could find no examples in the documentation, but I assumed I would get a different error message to help me figure it out.

RT version 4.4.2

Thanks!


#2

Without seeing the rest of the script/scrip its a bit tricky to help you debug this, but the error looks like it might be because you’re missing the RT:: part at the front of the calls so it doesn’t know what object you’re trying to call the Load() method on. You might want something like (for example):

my $cf = RT::CustomField->new($RT::SystemUser);
$cf->Load(4);

If this is a script rather than a scrip, remember that you’ll need to include use RT::Tickets and/or use RT::CustomField and probably call RT::LoadConfig(); and RT::Init();.


#3

I found what I needed with some additional forum scouring:

$cf_info = $TicketObj->FirstCustomFieldValue(Field => ‘4’);

I didn’t realize what was available from the RT::Record object.

Thanks though!


#4

Oops, more like:

$cf_info = $TicketObj->FirstCustomFieldValue(‘4’);