Posted on 2007-07-25 10:44:26-07 by netspot
REST and Custom Fields
Hi,

I don't know if this has been brought up, but I will continue with this post.

I have been working on a perl script which will create a ticket in RT using REST. I started using RT::Client::REST 0.31. One of the requirements was the ability populate custom fields on ticket creation. Also needed the ticket to contain all the information it needed from a form on ticket creation. I used RT::Client::REST->create subroutine to create the ticket which was great as I could populate all fields on creation, except for custom fields.

Why was this happening? Well, in REST.pm, it takes all the values provided in the hash in the create subroutine and makes them all lowercase. Custom fields need to start with "CF-" and in that case for them to work.

Fix:

Line 271, just after the line

while (my ($k, $v) = each(%$set)) {

I changed it from:

vpush(\%set, lc($k), $v);

to:

if ( $k =~ /^CF-/i ) { vpush(\%set, $k, $v); } else { vpush(\%set, lc($k), $v); }

After that change, custom fields were working.

I will include a snippet of the create subroutine to show you what I mean:

$rt->create(type => 'ticket', set => { 'queue' => 'testqueue', 'CF-Testing' => 'value for your custom field', 'status' => 'new', etc

I have put all hash values in ' ' for consistency.

Dmitri, would this be something you would add to the module in the next release?

Regards,

Alex
Direct Responses: 6654 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.