I’ve been asked by my RT users if there’s a way to dynamically render
custom fields in a given ticket. For instance, in one of our hardware
request queues, if a user would request 5 different hardwares with 3
different OS, middlewares, etc. They want to be able to specify 5 systems
and it would render 5 different fields. I know out of the box, RT does
not have this capability, but what I’d like to know, if this is doable and
has someone done this already and maybe perhaps point me to the right
direction.
Thanks in advance.
Enrique
I don’t know if you can auto-generate custom fields, but you can certainly
store multiple values within an already existing custom field. For
instance, set up custom fields for Hardware, OS, Applications, etc,
creating each field as a “multiple values” field. Each field can then hold
as many values as you like. Using a scrip to load values into the fields
is fairly straightforward and there are examples in the Contributions (or
Code Snippets, I can never remember which) area of the wiki.
Let me know if this doesn’t answer your question.
Regards,
Gene
At 03:19 PM 4/4/2007, Enrique Gaona wrote:
I’ve been asked by my RT users if there’s a way to dynamically render
custom fields in a given ticket. For instance, in one of our hardware
request queues, if a user would request 5 different hardwares with 3
different OS, middlewares, etc. They want to be able to specify 5 systems
and it would render 5 different fields. I know out of the box, RT does not
have this capability, but what I’d like to know, if this is doable and has
someone done this already and maybe perhaps point me to the right direction.
Thanks in advance.
Enrique
Gene LeDuc, GSEC
Security Analyst
San Diego State University
Gene,
Thanks for the suggestion. I’ll look through the Contributions for some
examples.
Enrique
Gene LeDuc
<gleduc@mail.sdsu
.edu> To
Enrique Gaona/Austin/IBM@IBMUS
04/05/2007 11:10 cc
AM RT User List
<rt-users@lists.bestpractical.com>
Subject
Re: [rt-users] Question about
autogenerating custom fields
I don’t know if you can auto-generate custom fields, but you can certainly
store multiple values within an already existing custom field. For
instance, set up custom fields for Hardware, OS, Applications, etc,
creating each field as a “multiple values” field. Each field can then hold
as many values as you like. Using a scrip to load values into the fields
is fairly straightforward and there are examples in the Contributions (or
Code Snippets, I can never remember which) area of the wiki.
Let me know if this doesn’t answer your question.
Regards,
Gene
At 03:19 PM 4/4/2007, Enrique Gaona wrote:
I’ve been asked by my RT users if there’s a way to dynamically render
custom fields in a given ticket. For instance, in one of our hardware
request queues, if a user would request 5 different hardwares with 3
different OS, middlewares, etc. They want to be able to specify 5 systems
and it would render 5 different fields. I know out of the box, RT does not
have this capability, but what I’d like to know, if this is doable and has
someone done this already and maybe perhaps point me to the right
direction.
Thanks in advance.
Enrique
Gene LeDuc, GSEC
Security Analyst
San Diego State University
Hi Enrique,
Here are the functions I use for populating and reading CFs in scrips and
templates. I just wrapped function headers around the the code I found in
the wiki. The get_custom_list function uses brute force to find the CF Id
because I got tired of trying to figure out how to get it by name, but it
works for me (I only have a template version because I haven’t had to read
multiple values in a scrip yet, but converting it for scrip use should be
trivial).
For scrips:
Sets custom field value
usage: set_custom($field_name, $field_value);
sub set_custom {
(my $CFName, my $CFValue) = @_;
my $CF_Obj = RT::CustomField->new($self->CurrentUser);
$CF_Obj->LoadByName(Name=>$CFName,);
$CF_Obj->AddValueForObject(Object=>$self->TicketObj, Content=>$CFValue,);
}
Returns custom field value (single value) or undefined
usage: $value = get_custom($field_name);
sub get_custom {
my $target_name = $_[0];
my $val = $self->TicketObj->FirstCustomFieldValue($target_name);
return $val
if defined $val;
return undef;
}
For templates:
Sets custom field value (works for single and multiple values)
usage: set_custom($field_name, $field_value);
sub set_custom {
(my $target_name, my $val) = @_;
my $CF_Obj = RT::CustomField->new($Ticket->CurrentUser);
$CF_Obj->LoadByName(Name=>$target_name,);
$CF_Obj->AddValueForObject(Object=>$Ticket, Content=>$val,);
}
Returns custom field value (single value only) or undefined
usage: $value = get_custom($field_name);
sub get_custom {
my $target_name = $_[0];
my $val = $Ticket->FirstCustomFieldValue($target_name);
return $val
if defined $val;
return undef;
}
Returns custom field values (multiple values) or undefined
usage: @list = get_custom_list($field_name);
sub get_custom_list {
my $target_name = $_[0];
my @ret;
my $CustomFields = $Ticket->QueueObj->TicketCustomFields();
while (my $CustomField = $CustomFields->Next()) {
if ($CustomField->Name eq $target_name) {
my $CustomFieldValues = $Ticket->CustomFieldValues($CustomField->Id);
while (my $val = $CustomFieldValues->Next()) {
push @ret, $val->Content;
}
return @ret
if defined @ret;
return undef;
}
}
return undef;
}
Regards,
Gene
At 06:13 AM 4/6/2007, Enrique Gaona wrote: