- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Included in the Developer Toolbox Update Set available on Share (link to Share in the post).
The Suggestion Field Type is a bit of a pain to work with on fields that are inherited, like "Short description" on the Task table. And it's not even a true Field Type, more of an added feature of String fields. The feature allows you to add pre-defined values by setting the "Choice" field to "Suggestion":
This will add a lightbulb icon to the right of a field:
Clicking the icon will open a window with a list of pre-defined values to select from:
You can also start typing in the field to get a list of values that match what you are typing:
Overall, it's a nice feature, BUT, there are some issues with it:
- the icon appears even if there are no suggestions to select from for that table's inherited field
- because of how it is configured, you cannot hide the icon on inherited fields you don't want it on (no Dictionary Override capability)
I've come up with a workaround that replaces the functionality, allowing you to use it on just the fields you want it on. One caveat - the type-ahead feature is not supported. But that may not be a big deal for most implementations.
First, we create a new UI Macro that does all the work:
Name: u_fpc_show_suggestions
XML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate >
var title = gs.getMessage("u_fpc_show_suggestions.title");
var table = "${ref}".split(".")[0];
var element = "${ref}".split(".")[1];
var choices = 1; // set to 0 if you want to check for options (not the most efficient)
/* remove matching block comments if you want to check for options (not the most efficient)
//check the Choices table to see if there are any suggestions for this field
var count = new GlideAggregate("sys_choice");
count.addAggregate("COUNT");
count.addEncodedQuery("inactive=false^name=" + table + "^element=" + element);
count.query();
if (count.next()) {
choices = count.getAggregate("COUNT");
}
*/
//hide or show the icon based on whether there are choices or not
var style = choices == 0 ? "display: none" : "display:";
</g2:evaluate>
<a id="u_fpc_show_suggestions.${ref}" name="u_fpc_show_suggestions_${ref}" data-type="pick_list" data-ref="${ref}" data-table="$[table]" data-element="$[element]" data-dependent="null" tabindex="-1" role="button" class="btn btn-default btn-ref" title="$[title]" style="$[style]">
<span class="icon icon-lightbulb" style=";"></span>
</a>
</j:jelly>
You can add a Message record to contain the hint for the icon, but it's probably just easier to hard-code it right into the UI Macro (lines 4/5). I like to use Message and System Property records instead of hard-coding things, but you should weigh the costs versus benefits before creating too many user-definable settings. For instance, a Message record here would be perfect in a multilingual instance.
There is some commented out code that verifies if there are entries available or not. If there are none, the icon is hidden. This does not necessarily make sense in normal implementation as you wouldn't add the feature to a field unless you have some values setup in the Choice table. But, there could be some scenarios where this make sense, so you set "choices = 0" on line 8 and remove lines 9 and 18 to add the check.
To add the icon to a field, add the name of the UI Macro to the field's "field_decoration" dictionary attribute. For instance, to disable the OOB functionality on the Task's Short description field, set the Choice field to "-- None --":
That will remove the icon from all Short description fields on tables extended from Task. Then, create a Dictionary Override for the Incident table and override the attributes field:
The contents of the "Attributes" field will, of course, depend on your particular implementation, so it may vary from the above. The important thing here is adding the "field_decorations=u_fpc_show_suggestions" part.
This will then add the lightbulb icon beside the Short description field on the Incident table only. To add it to others, just create new or modify existing Dictionary Override records and add the "field_decorations=u_fpc_show_suggestions" attribute.
Now we have the Short description on Incident with the icon:
...and Short description on Change Request without the icon:
And the nice thing about this solution is there's no DOM manipulation involved to hide the icon on the fields that it should not appear with.
- 4,596 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.