https://rt-wiki.bestpractical.com/index.php?title=ApproximateSeparateQueues&feed=atom&action=historyApproximateSeparateQueues - Revision history2024-03-28T23:30:17ZRevision history for this page on the wikiMediaWiki 1.37.2https://rt-wiki.bestpractical.com/index.php?title=ApproximateSeparateQueues&diff=189&oldid=prevAdmin: 3 revisions imported2016-04-06T20:03:15Z<p>3 revisions imported</p>
<p><b>New page</b></p><div>= Using LDAP and custom fields to approximate separate queues =<br />
<br />
We use Request Tracker in our school system across eight separate elementary and secondary schools. All tickets feed into a single "Incidents" queue, but each building has its own technician, and I want RT to notify the building tech when a staff member from that building submits a ticket. The process proceeds in two distinct steps:<br />
<br />
# Query our LDAP server to set a ticket custom field that identifies the requestor's school<br />
# Based on the value of that custom field, notify the tech (or techs) at that school.<br />
<br />
== Step 1: Set the custom field ==<br />
<br />
I created a new scrip called "Set Building CF from LDAP" with the following settings:<br />
<br />
'''Condition:''' On Create<br />
<br />
'''Action:''' User Defined<br />
<br />
'''Template:''' Global template: Blank<br />
<br />
'''Custom action preparation code:''' <code>return 1;</code><br />
<br />
'''Custom action cleanup code:'''<br />
<br />
<nowiki>my $mail = ($self-&gt;TicketObj-&gt;RequestorAddresses)[0];<br />
my $ldap = Net::LDAP-&gt;new( '10.1.10.230' );<br />
$ldap-&gt;bind;<br />
<br />
# Do the LDAP search. Note: Our eDirectory server uses "mail" for the<br />
# user's email address.<br />
my $msg = $ldap-&gt;search( base =&gt; 'ou=Staff,o=Example',<br />
filter =&gt; "(mail=$mail)",<br />
);<br />
my $entry = $msg-&gt;entry(0);<br />
# Each user is a member of an ou which corresponds to his or her school<br />
my $ou = $entry-&gt;get_value('ou');<br />
<br />
# The value of the ou isn't what I want to put in the custom field so<br />
# map the ou value to the corresponding custom field value.<br />
my %building_for = (<br />
'DISTRICT SERVICES' =&gt; 'DO',<br />
'HIGH SCHOOL' =&gt; 'BHS',<br />
'MIDDLE SCHOOL' =&gt; 'BCMS',<br />
'LINCOLN' =&gt; 'LES',<br />
'_DEFAULT_' =&gt; 'DO',<br />
);<br />
my $building = $building_for{$ou} || $building_for{_DEFAULT_};<br />
<br />
my $cf = RT::CustomField-&gt;new( $RT::SystemUser );<br />
$cf-&gt;LoadByName( Name =&gt; 'Building' );<br />
$self-&gt;TicketObj-&gt;AddCustomFieldValue( Field =&gt; $cf, Value =&gt; $building );<br />
<br />
return 1;<br />
<br />
</nowiki><br />
<br />
With this scrip in place, every incoming ticket has its "Building" custom field set to the requestor's school.<br />
<br />
== Step 2: Notify the building tech ==<br />
<br />
I created a second scrip to trigger whenever the "Building" custom field is changed. It has these settings:<br />
<br />
'''Description:''' Notify techs of new tickets<br />
<br />
'''Condition:''' User Defined<br />
<br />
'''Action:''' Notify Other Recipients<br />
<br />
'''Template:''' Building Tech Notify<br />
<br />
The custom condition code looks like this:<br />
<br />
unless (<br />
( $self-&gt;TransactionObj-&gt;Type eq "CustomField"<br />
&amp;&amp; $self-&gt;TransactionObj-&gt;Field == 10 )<br />
|| $self-&gt;TransactionObj-&gt;Type eq "Create"<br />
) {<br />
return 0;<br />
}<br />
<br />
1;<br />
<br />
<br />
More information about triggering scrips on custom field changes can be found at the [[CustomConditionSnippets#Checks_with_Custom_Fields]] page of the wiki.<br />
<br />
In order to notify the proper tech that a new ticket has been created, I created an RT group for each building. The group names are of the form "SupportTeam-X" where X is the building code found in the "Building" custom field of each ticket. With this approach I can notify more than one tech at a building by making sure each tech is a member of his or her building group. The code to examine the group members is in the following "Building Tech Notify" template.<br />
<br />
<nowiki>To: { my $bldg = $Ticket-&gt;FirstCustomFieldValue('Building');<br />
my $group = RT::Group-&gt;new( $RT::SystemUser );<br />
$group-&gt;LoadUserDefinedGroup("SupportTeam-$bldg");<br />
$group-&gt;MemberEmailAddressesAsString; }<br />
Subject: Notify: {$Ticket-&gt;Subject}<br />
<br />
Greetings,<br />
<br />
A new ticket has been created, and it looks like it's from {<br />
my $users = $Ticket-&gt;Requestors-&gt;UserMembersObj;<br />
my $output = '';<br />
while( my $user = $users-&gt;Next ) {<br />
$output .= ', ' if $output;<br />
$output .= $user-&gt;RealName; # or any other user's property<br />
}<br />
$output;<br />
} at {$Ticket-&gt;FirstCustomFieldValue('Building')}. Here's the original message:<br />
<br />
--snip--<br />
{$Ticket-&gt;Transactions-&gt;First-&gt;Content()}<br />
--snip--<br />
<br />
If you're ready to start working on this ticket, you can do so at the following URL or by responding to the requestor directly by replying to this message:<br />
<br />
{ $RT::WebURL }Ticket/Display.html?id={ $Ticket-&gt;Id() }<br />
<br />
-RT<br />
<br />
</nowiki><br />
<br />
Besides notifying the building tech, this template also prints the name of the requestor in the body of the message.<br />
<br />
This approach has worked well for us. We could have created separate RT queues for each building, but this approach achieves a similar degree of separation while enabling the building techs to collaborate on tickets more conveniently. Each tech has created a custom "RT at a glance" page which utilizes a saved search to display the newest tickets from their school.<br />
<br />
== Acknowledgements ==<br />
<br />
Thanks to Keith Schincke, Ruslan Zakirov, Gene LeDuc, Robert Long, David Narayan, and Kenneth Crocker for providing timely advice on the RT-users mailing list.<br />
<br />
Submitted by [[TimWilson]]. Feel free to send me a message via the RT-users mailing list if you have any questions.<br />
<br />
----<br />
<br />
== Active Directory ==<br />
<br />
Edit By David Kirk<br />
<br />
When using this with Active Directory, I had to do the following to make it work:<br />
<br />
while( my $entry = $msg-&gt;shift_entry) {<br />
<br />
my $dn = $entry-&gt;dn;<br />
<br />
my $ounum=0;<br />
<br />
my $[[SecondOU]];<br />
<br />
foreach my $dnparts(split (',',$dn)) {<br />
<br />
my %attributes=split('=',$dnparts);<br />
if (defined $attributes{"OU"}) {<br />
$ounum++;}<br />
if ($ounum==2){<br />
$SecondOU=$attributes{"OU"};<br />
$ounum++;}<br />
<br />
}<br />
<br />
I use the second OU up from the user to determine what queue it is assigned to.</div>Admin