<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:#606420;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink="#606420">
<div class=Section1>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>Hi everyone,<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>I would like to take some of your
time to inquire about the following and I will appreciate if someone could
help.<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>I am using RT 3.6.3 on a Fedora core
8 Box. <o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>This is my dilemma: I am writing a
Perl script that enables me to create custom fields from an external Excel
spreadsheet. I would like to create one custom field and apply it
to a number of queues, just as we can do that manually using the web
interface. <o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>In the beginning, I have used the
following API:<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'> my $system_user =
initialise_rt();<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'> my $rtObj_cf =
RT::CustomField->new($system_user);<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'> my $rt_queue =
RT::Queue->new($system_user);<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>foreach my $queue ( keys %{
$rec->{queue_record} } ) {<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
</span></font><font size=2 face=Arial><span lang=FR style='font-size:10.0pt;
font-family:Arial'>print "queue: $queue \n";<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
lang=FR style='font-size:10.0pt;font-family:Arial'>
my $queue_id = $rt_queue->Load($queue);<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
lang=FR style='font-size:10.0pt;font-family:Arial'>
print qq~queue id: $queue_id\n~;<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
lang=FR style='font-size:10.0pt;font-family:Arial'>
</span></font><font size=2 face=Arial><span style='font-size:10.0pt;font-family:
Arial'>next if ( !defined $queue_id || !$queue_id || $queue eq '' );<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
foreach my $cf ( keys %{ $rec->{lcf_record} } ) {<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
if ( defined $rec->{lcf_record}{$cf}{Pattern} &&
$rec->{lcf_record}{$cf}{Pattern} ne '' &&
$rec->{lcf_record}{$cf}{Pattern} =~ /Yes|Mandatory/i ) {<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
foreach my $site ( keys %{ $rec->{site_record} } ) {<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
<b><span style='font-weight:bold'>my ( $id, $msg ) = $rtObj_cf->Create(<o:p></o:p></span></b></span></font></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
</span></font></b><b><font size=2 face=Arial><span lang=FR style='font-size:
10.0pt;font-family:Arial;font-weight:bold'>Name
=> $site. '_' . $queue . '_' . $cf,<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
lang=FR style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
</span></font></b><b><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial;font-weight:bold'>Queue
=> $queue_id,<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
Description => 'Custom Field ' . $site. '_' . $queue . '_' . $cf,<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
Pattern => '(?#Mandatory).',<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
SortOrder => '1',<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
Type =>
$rec->{lcf_record}{$cf}{Type}<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
);<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
if ( !$id ) {<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
print qq~Problem to create the costum field: $cf, message: $msg \n~;<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><b><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-weight:bold'>
next;<o:p></o:p></span></font></b></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
}<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>
$rtObj_cf->Load($id);<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>The following segment of code loops
through all queues defined in the excel spread-sheet and create custom fields
for each queue according to the number of custom fields I have. So, if I
have 3 custom fields in the excel sheet and 4 queues, then the total number of
custom fields is 12. <o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>The problem with this approach is
that you create redundant custom fields (or access custom fields). What I
would like to do is to take advantage, using a script; of the facility of which
RT 3.6.0+ can create custom fields and apply them to each queue. So,
instead of creating 12 custom fields, I need to create 3 custom fields and
apply to all queues.<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>Is there an API that one could use,
after creating the custom field, to apply the custom field to the queue under
question?<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>Thanks and I apologize for the inconvenience<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'> <o:p></o:p></span></font></p>
<p><font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Thanks</span></font>
<br>
<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Firas</span></font>
<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Batal</span></font><o:p></o:p></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>