g:ui_reference display choices based on dependent field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 01:25 PM
Hi guys,
I have a requirement to close multiple incidents at the same time via a UI action (list choice). I need to prompt users with some fields on a dialog box for them to select values to be reflected to the selected records.
One of my fields on the dialog box is of String type with around 1k choices. The choices that would display is based on the value of a dependent field called Business Service. How do I implement this in g:ui_reference?
The result should be something like this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 01:28 PM
Choice type fields are great but really meant for a small number of choices. I would recommend moving these 1000 choices to a custom table and then changing the field to a reference where you can leverage a reference qualifier to filter the reference selection based on the other field much easier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 01:34 PM
Thanks Michael for the reply.
I'm not sure If I can move the choices to a table given the timeframe that I have. But is this possible to implement my requirement using g: ui_reference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 01:42 PM
Unfortunately choice type fields behave differently because all the choices are put into memory and available client side. This is another reason not to have too many choices because every-time you load the form those values are sent to each user viewing it.
Choice type fields can be dependent on a field. If you look at the out of the box Category and Subcategory on the incident table, they behave this way. You select a category and the subcategories are filtered based on that category selection. The way this is being done is there is a "Dependent value" field on the sys_choice table that needs to be filled in with the value from the dependent field. You can add this column to your Choices list and set it as appropriate.
Otherwise you are stuck with client scripting using the removeOption function which will get pretty hairy with that many choices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 01:49 PM
I thought maybe this is possible by using sys_choice table and use the query highlighted below? But how do I pass the selected value from g:ui reference onto the query for classification field so that the sys_id is dynamic and based on what's selected from the Business Service?
nameSTARTSWITHincident^dependent_value=d65a6771f561f1842f4a61d4c74cbf0f <---dynamic
<!-- Business Service Field -->
<div class="form-group">
<label class="reference-label">${gs.getMessage('Business Service')}</label>
<g:ui_reference name="bus_svc" table="u_cmdb_ci_service_business" show_popup="true" show_lookup="true" query="active=true" />
</div>
<!-- Classification Field -->
<div class="form-group">
<label class="reference-label">${gs.getMessage('Classification')}</label>
<g:ui_reference name="bus_svc" table="sys_choice" show_popup="true" show_lookup="true" query="nameSTARTSWITHincident^dependent_value=d65a6771f561f1842f4a61d4c74cbf0f" />
</div>