[Rt-devel] How to Update CustomField values

Simone Sanna simone.sanna at tinet.net
Fri Nov 12 11:42:52 EST 2010


Hello List,
I need to update the values of a given customfield, I mean be able to 
change anything in Name, Description,  SortOrder and Category, based on 
the customfield value Id associated.
I have found how to show, add and delete, that I need too, but in 
CustomField_Overlay.pm, there is nothing called *Update* and  I couldn't 
find anything clear that could let me update a customfield, I mean 
change its values keeping the same Id.

Could someone show me how to do that or refer me to some examples?

Many thanks in advance.

Kind regards,
Simone




#!/usr/bin/perl
use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
use RT;
use RT::Date;
use RT::Queue;
use RT::Tickets;
use RT::Action::RecordComment;
use RT::Transaction;
use RT::CustomFields;


RT::LoadConfig();
RT::Init();


new RT::Ticket($RT::SystemUser);
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Severity";


$cf_obj->LoadByName( Name => $cf_name );

print ("Loaded \$cf_obj->Name = ". $cf_obj->Name() . " " . $cf_obj->Id() 
. "\n");

### This adds a new value
$cf_obj->AddValue(Name=> 'Critical', Description=> 'Critical',  
SortOrder => '0');

### This updates the customfield value for a given id
???????

###This deletes a customfield value for a given id
$cf_obj->DeleteValue(##);

###This shows how to get the defined values of the customfield, along 
with IDs, and sort orders.
$values = $cf_obj->Values();
while(my $value = $values->Next){
print $value->Name() . "--" . $value->Id() . "--" . $value->SortOrder() 
. "\n";
}

-- 
Simone Sanna
Spectrum&  IT Policies System Administrator
TINET SPA
Località Sa Illetta S.S.195 Km.2,300
09122 Cagliari (ITALY)
Ph. +39 0704600728
E-mail: simone.sanna at tinet.net



More information about the rt-devel mailing list