<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Here 'tis.<br>
<br>
My addition to the Create {} subroutine is lines 130-138. The check
for uniqueness and auto-choosing the next highest number happen in
additional subroutines beginning at line 230.<br>
<br>
We call the relevant field "COE Number" (sometimes "CoE Number", the
case seems not to matter); change that wherever I have it to
whatever you call your field.<br>
<br>
Lines 133 and 137 are where I needed to know that the custom field
was #1 ('CustomField-1'). There are two SELECT queries, one (line
322) where I searched for the field by name and one (line 244) where
I searched for it by number. Probably I should have done both of
those the same way, for clean code purposes. Probably searching by
name would be the way to go, for even cleaner code purposes.<br>
<br>
We assume that we'll be adding (whenever I get this live) existing
assets to a clean database, so we accept input for the COE Number.
I do some basic testing, to make sure that if there is input, it is
a number and not, say, an SQL command. I don't do any sort of
sanity checking on the given number, except to see if it's already
in use; someone could, for instance, input "1000000" instead of
"1000" and kick our asset numbers up a few orders of magnitude.
Probably with some additional work the getNextNumber subroutine
could look for such gaps and fill them in, but I don't think I'll be
getting around to that extra work anytime soon.<br>
<br>
I believe there are some rigorous tests that can be used on RT
extensions; I have not done anything of that sort with this code.
I've only played with it on a couple of test systems (both RT 4.2),
but it so far does what I want it to.<br>
<br>
If you have any questions, I'll try to answer, hopefully with
something better than "It made sense at the time".<br>
<br>
If any accomplished programmers would like to shred it and tell me
everything I could do better, I'd appreciate the education.<br>
<br>
Share and enjoy,<br>
Kyle<br>
<br>
<div class="moz-cite-prefix">On 03/15/2016 12:34 PM, Seever, Kenny
wrote:<br>
</div>
<blockquote
cite="mid:6DD4000378C57D45A709CA0B1CB54C3419623AE3@ATCPMX03.mwgp.net"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Kyle,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks for the
reply. If possible would you be willing to share what you
have? This will be something I’ve never attempted so need
all the help I can get.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks again,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Kenny<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span
style="color:windowtext"> Kyle Dippery
[<a class="moz-txt-link-freetext" href="mailto:kyle.dippery@uky.edu">mailto:kyle.dippery@uky.edu</a>]
<br>
<b>Sent:</b> Monday, March 14, 2016 8:34 AM<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:rt-users@lists.bestpractical.com">rt-users@lists.bestpractical.com</a><br>
<b>Cc:</b> Seever, Kenny
<a class="moz-txt-link-rfc2396E" href="mailto:Kenny.Seever@mgpingredients.com"><Kenny.Seever@mgpingredients.com></a><br>
<b>Subject:</b> Re: [rt-users] Unique custom fields for
assets<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Kenny,<br>
<br>
I haven't looked at RT 4.4 yet, so perhaps it's built in
there, but it wasn't in RT 4.2.<br>
<br>
What you will need to do, if it isn't there already, is create
your own extension to the Asset.pm module, call it
Asset_Local.pm, and add code there to check for uniqueness and
auto-populate the field. The Create {} subroutine is the one
you'll most likely want to override.<br>
<br>
One gotcha that I remember (I did this about a year ago) is
that I needed to know the number of the custom field; I
couldn't figure out how to search the $args{} array for the
field by name. That being our most critical custom field,
though, it made sense to create it first so it would be
"CustomField-1".<br>
<br>
I'm reluctant to post my actual code, because it's crappy and
I don't want to release bad code into the wild, but if you'd
like to see it I can sanitize it some and share it.<br>
<br>
Cheers,<br>
Kyle<span style="font-size:12.0pt"><o:p></o:p></span></p>
<div>
<p class="MsoNormal">On 03/11/2016 11:38 AM, Seever, Kenny
wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hello, <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I am working on evaluating using the
Assets module in RT to manage our equipment, but haven’t
been able to figure out if there is a way to make a field
unique. All of our equipment has a 5 digit asset number
(2XXXX) that is unique. I need to be able to add a field
that makes sure that each number is only used once. Ideally
it would auto populate with the next number when a new asset
is added, but that may be asking for too much. Is there
build in functionality for any of this that I’ve missed in
the documentation?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks in advance,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Kenny<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><span
style="font-size:12.0pt;font-family:"Times New
Roman",serif"><br>
<br>
<o:p></o:p></span></p>
<pre>-- <o:p></o:p></pre>
<pre>Kyle Dippery<o:p></o:p></pre>
<pre>Engineering Computing Services<o:p></o:p></pre>
<pre>219 RMB<o:p></o:p></pre>
<pre>859-257-1346<o:p></o:p></pre>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Kyle Dippery
Engineering Computing Services
219 RMB
859-257-1346
</pre>
</body>
</html>