AD Lookup Control in Request Tracker
So my double header post on getting this funky AD lookup control with Perl (post 1 & post 2) was actually prep work for getting to work in a product called RT (or Request Tracker from BestPractical) which is built on Perl. I have never worked with it before so I am slightly (read: exceptionally) ignorant of how to do this. Effectively I want a lookup to include AD users.
The First Option
The first thing I saw was this Include Page option when creating a field, which is described as
RT can include content from another web service when showing this custom field. Fill in this field with a URL. RT will replace __id__ and __CustomField__ with the record id and custom field value, respectively Some browsers may only load content from the same domain as your RT server.
Sounds perfect, turns out there is NO knowledge of how this works. I tried various forums and news groups, even emailing people who asked before about it… no answers are available! The documentation is USELESS!
The Second Option
Another option is once you have created a field a new option appears: Field values source:
So how do you actually use this without typing in the options yourself?
Custom Perl Module
Well in the /opt/rt3/lib/RT/CustomFieldValues is a file called Groups.pm which allows you to provide the names of the groups as a field source. So this is a possible solution, but first you need to create the module. The module has two methods:
SourceDescription - Which needs to return a string containing the name of what you are returning.
ExternalValues - Which needs to return an array of objects which contain the values. Those object must have a name property which is the name you want to show, and two optional properties description which is the… actually I dunno where it’s used (don’t think it is) and sortorder which you use to do the sorting. So taking the AD code previous the previous posts and combining it into the right format we end up with this code:
So we bundle that nicely in to AD.pm and dump that into the folder.
So how do we use that module? Well you need to go to /opt/rt3/etc and edit the RT_SiteConfig.pm file and add the following line to it: Set(@CustomFieldValuesSources, "RT::CustomFieldValues::AD");
Next restart Apache (the command I used was: apache2ctl restart) and go back to the field properties and you should be able to select it.
Tips and Tricks
A few things about building these that I learnt along the way
- If, after the IIS reset, there is no drop down for the field source it means you have a bug in a module and you need to fix said bug.
- Use the die command excessively. When you select the field source and click save changes it will test your code. Only die will cause it to show error messages! When you get the UI, it will not give you errors!
- If you change the code after you have set the field, you need to restart apache and then re-configure the field by setting the field source to something else, save and then set it back. It seems there is some caching issues which can prevent your changed results from appearing.
Hopefully this helps you develop with RT, and that this (overcomplicated) process is easier.