Create a custom Select Values action
Create a custom Select Values action
Technologies > User Interface Add-Ins > Parts for Forms > Custom Select Value Buttons
The select value dialog may be customized for many purposes:
- display a subset of values from which to choose by placing a restriction on the values
- use a table and field other than the input table and field from which to select values
- customize which fields are visible in the dialog
The
selectValue
command attributes are detailed in the Command Reference:
selectValue
.
The tree control version of the Select Value dialog is used automatically for N-tier hierarchy fields. You can force a regular field to use the Tree Select Value dialog in AXVW:
Use a tree as a Select Values control
Per-field actions
In addition to customizing the Select Value dialog button, you can add additional buttons to any form field. These action buttons are displayed next to the field input control.
An example of a per-field action for displaying a custom Select Value dialog is shown below:
<panel type="form">
<field table="rm" name="dp_id">
<field table="rm" name="dv_id">
<action>
<title>...</title>
<tooltip>Custom Select Value</tooltip>
<command type="selectValue"
fieldNames="rm.dp_id, rm.dv_id"
selectFieldNames="dp.dp_id, dp.dv_id"
visibleFieldNames="dp.dv_id, dp.dp_id, dp.name"
restriction="dp.dp_id LIKE 'SOFT%'"/>
</action>
</field>
</panel>
This will display the Select Value dialog with following properties:
- The dialog will display all records from the dp table that meet the specified SQL restriction.
- The dialog will display three fields from the dp table: dp.dv_id, dp.dp_id, dp.name.
- When the user selects a record in the dialog, the selected dp.dv_id value will be copied into the rm.dv_id field value on the form, if it exists. The selected dp.dp_id value will be copied into the rm.dp_id field value on the form.
- If, prior to opening the Select Value dialog, the user has already entered any value into the rm.dv_id field, they will be used as a filter to limit the records displayed in the Select Value dialog. The user will be able to remove the filter values in the dialog.
Binding expressions
Select Value restrictions can also contain binding expressions like
${record['wrcf.wr_id']}
,
${user.employee.id}
or
${sql.currentDate}
. These binding expressions can be used both in XML or in Javascript.
<command type="selectValue"
applyFilter="false">
fieldNames="wrcf.cf_id"
selectFieldNames="cf.cf_id"
visibleFieldNames="cf.cf_id,cf.tr_id,cf.work_team_id,cf.email"
restriction=" exists (select 0 from em where em.email = cf.email and em.bl_id in(select bl_id from bl where site_id = (select site_id from wr where wr_id = '${record['wrcf.wr_id']}'))) and (date_contract_exp IS NULL OR date_contract_exp > ${sql.currentDate})">
<title>Craftsperson</title>
</command>
Sorting
You can also choose to sort data. For example, to sort the selection list employees by the name_last and name_first fields:
<command type="selectValue"
fieldNames="wr.requestor"
selectFieldNames="em.em_id"
visibleFieldNames="em.em_id,em.name_last, em.name_first,em.phone,em.email"
sortFieldNames="em.name_last, em.name_first"/>
Field order
When an application view or JavaScript function creates a custom select value dialog, the field names must be ordered such that any parent fields precede the current field. For example, when writing a custom select value command in an AXVW for a work request's activity_log.rm_id field, the select value's
fieldNames
parameter must be ordered as
activity_log.bl_id,activity_log.fl_id,activity_log.rm_id
rather than
activity_log.rm_id,activity_log.fl_id,activity_log.bl_id
. The first list has the current field (activity_log.rm_id) as the last field. This allows the filtering of any existing form values to work correctly when opening the dialog.
Custom field titles
By default, the Select Value dialog displays field titles defined in the schema (i.e. in the AFM Fields table). Add-in managers can specify custom titles using the Java Script API:
View.selectValue({
formId: 'rmFilterPanel',
title: 'Select Floor',
fieldNames: ['bl.site_id','rm.bl_id','rm.fl_id'],
selectTableName : 'bl',
selectFieldNames: ['bl.site_id','fl.bl_id','fl.fl_id'],
visibleFields: [
{fieldName: 'bl.site_id', title: getMessage('titleBldgSite')},
{fieldName: 'fl.bl_id', title: getMessage('titleBldgName')},
{fieldName: 'fl.fl_id', title: getMessage('titleFloorId')},
{fieldName: 'fl.name', title: getMessage('titleFloorName')}
]
});
The localized field titles should be defined in the AXVW view file using
<message>
elements.
Example:
Sort Fields in Select Value dialog
Add-in managers can specify the initial sort order for the Select Value dialog:
View.selectValue({
formId: 'rmFilterPanel',
title: 'Select Floor',
fieldNames: ['bl.site_id','rm.bl_id','rm.fl_id'],
selectTableName: 'bl',
selectFieldNames: ['bl.site_id','fl.bl_id','fl.fl_id'],
visibleFields: [
{fieldName: 'bl.site_id', title: getMessage('titleBldgSite')},
{fieldName: 'fl.bl_id', title: getMessage('titleBldgName')},
{fieldName: 'fl.fl_id', title: getMessage('titleFloorId')},
{fieldName: 'fl.name', title: getMessage('titleFloorName')}
],
sortFields: [
{fieldName: 'fl.name', sortAscending: false},
{fieldName: 'fl.bl_id', sortAscending: true}
],
});
The initial sort order can include multiple fields.
The user can re-sort the records by clicking on a column header. However, this will always produce a sort order based on a single field.
Note that in the case above, the order in which the
selectFieldsNames
appear in the Select Value dialog may be affected by the value of
selectTableName
. Fields which are selected from the main table, as determined by the value of
selectTableName
appear before fields taken from a standard table.
Example:
Disabling VPA restrictions
When a VPA restriction for validated tables is used on building, in a form selecting an employee, the select value will only select employees located in this building. In some use cases one may also want to select an employee in another building, overriding the default behavior defined by the VPA restriction.
The new property can be set in AXVW command:
<command type="selectValue" ... applyVpaRestrictions="false">
or in JS code: (For an example, see /schema/ab-products/solutions/parts/form/ab-ex-form-panel-select-value.js)
View.selectValue({
...
applyVpaRestrictions: false,
...
});
Example:
http://localhost:8080/archibus/ab-ex-form-panel-select-value.axvw
Adding restrictions on secure tables
When the Select value dialog needs to display records restricted by data from security tables, such as the users role or user-process assignments, you cannot use an SQL restriction in the command, as documented above. Instead, define a data source that provides restricted records and specify its ID in the dataSource property of the selectvalue command:
<command type="selectValue" ... dataSource="approvalManagers">
The data source must be defined in the same view as the command.
Example:
http://localhost:8080/archibus/ab-ex-form-panel-select-value.axvw