<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=ToggleCFs</id>
	<title>ToggleCFs - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=ToggleCFs"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=ToggleCFs&amp;action=history"/>
	<updated>2026-08-25T07:37:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=ToggleCFs&amp;diff=3891&amp;oldid=prev</id>
		<title>Admin: 3 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=ToggleCFs&amp;diff=3891&amp;oldid=prev"/>
		<updated>2016-04-06T20:39:29Z</updated>

		<summary type="html">&lt;p&gt;3 revisions imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
==Toggle Custom Fields==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The following only works with RT 4.x&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We had a need to show/hide custom fields depending on the value chosen for a certain &amp;quot;control&amp;quot; field. That is, if the control field had a certain value, we wanted to show a certain set of custom fields for editing and display. If the control field did not have that value, we wanted to hide those custom fields entirely.&lt;br /&gt;
&lt;br /&gt;
This could probably have been done easier in Javascript, but nobody on our team knows Javascript.&lt;br /&gt;
&lt;br /&gt;
Note that the following code is for&lt;br /&gt;
 local/html/Callbacks/MyCallbacks/Elements/ShowCustomFields/MassageCustomFields&lt;br /&gt;
&lt;br /&gt;
And the callback at (not the same path as above!):&lt;br /&gt;
&lt;br /&gt;
 local/html/Callbacks/MyCallbacks/Ticket/Elements/EditCustomFields/MassageCustomFields&lt;br /&gt;
&lt;br /&gt;
is nearly identical to this code below. &amp;#039;&amp;#039;&amp;#039;You&amp;#039;ll need both callbacks in place to hide/show CFs while on the Modify.html and on the Display.html page. No reason to paste code twice.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 %# local/html/Callbacks/MyCallbacks/Elements/ShowCustomFields/MassageCustomFields&lt;br /&gt;
 %#&lt;br /&gt;
 %# If ticket is not &amp;quot;Noteworthy&amp;quot; do not display a certain&lt;br /&gt;
 %# set of custom fields to the user.&lt;br /&gt;
 %#&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;%args&amp;gt;&lt;br /&gt;
 $CustomFields =&amp;gt; undef&lt;br /&gt;
 $ARGS =&amp;gt; undef&lt;br /&gt;
 $Object =&amp;gt; undef&lt;br /&gt;
 &amp;lt;/%args&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;%init&amp;gt;&lt;br /&gt;
 my $ticket = $Object;&lt;br /&gt;
 my $showchildren = 1;&lt;br /&gt;
 # We&amp;#039;re calling these togglable fields &amp;quot;child&amp;quot; fields&lt;br /&gt;
 # Don&amp;#039;t make too much of the nomenclature.&lt;br /&gt;
 my @childfields = ( &amp;quot;Child1&amp;quot;,&lt;br /&gt;
                     &amp;quot;Child2&amp;quot;,&lt;br /&gt;
                     &amp;quot;MyChild&amp;quot;,&lt;br /&gt;
                     &amp;quot;Noodle&amp;quot;&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 while (my $cf = $CustomFields-&amp;gt;Next) {&lt;br /&gt;
     my $nam = $cf-&amp;gt;Name;&lt;br /&gt;
     my $val = $ticket-&amp;gt;FirstCustomFieldValue($nam);&lt;br /&gt;
     if ($nam =~ /^noteworthy$/i and $val !~ /^yes$/i) {&lt;br /&gt;
         $showchildren = 0;&lt;br /&gt;
         last;&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 if (! $showchildren) {&lt;br /&gt;
     # &amp;quot;Remove&amp;quot; each child field from $CustomFields to not show it&lt;br /&gt;
     for (@childfields) {&lt;br /&gt;
         # &amp;quot;Limit&amp;quot; is part of DBIx-SearchBuilder (google it)&lt;br /&gt;
         $CustomFields-&amp;gt;Limit(FIELD =&amp;gt; &amp;#039;Name&amp;#039;, OPERATOR =&amp;gt; &amp;#039;!=&amp;#039;,&lt;br /&gt;
                              VALUE =&amp;gt; &amp;quot;$_&amp;quot;, ENTRYAGGREGATOR =&amp;gt; &amp;#039;AND&amp;#039;,&lt;br /&gt;
                              CASESENSITIVE =&amp;gt; 0);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/%init&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>