Skip to main content

What is Assistance type for Multi value list

Assistance type helps to fetch data for a given property page multi value list field.

What are the assistance types supported

Following assistance types are supported as part of multi value list fields:

  • DQL
  • Dictonary
  • Java

How to add assistance types for dropdown fields

Following attributes can be added to dropdown field to support fetching data.

assistance_type : This attribute specifies what type of assitance this field is refering to. It could be one of dql (or) dictonary (or) java.

assistance_{option} : This attribute provides the data source details for the given assistance type. If assitance_type is dql, then DQL query will be specified as part of this field. In case of java, we need to specify the Java class that returns the data.

asynchronous : This attribute specifies whether the data need to be fetched when the property dialog is opened (or) when dropdown is selected. if it is true, then data is fecthed when dropdown is selected by user.

depdendencies : This attribute is used when a field values presented using another dependent field. Multiple dependency fields can be added using comma as separator.

Example

Below example returns available D2 property config pages by using assistance type as DQL.

     <combo advancedView_required="true"
assistance_dql="select object_name from d2_property_config"
assistance_type="dql"
condition_required="true"
condition_required_edit="true"
control="true"
id="property_config"
label_en="Select view"/>

When data is fetched for dropdown fields

As part of custom dialog dropdown list fields, data can be fetched at the time of loading a dialog or when dropdown is selected by user.

Synchronous

During property dialog load, respecitive assistance type will be evaluated and data will be fetched and is available in the dialog.

Asynchronous

Data won't be fetched when the property dialog, rather it will be fetched when dropdown is selected.

Example

Below example returns available assistance types by using assistance type as Java.

     <combo advancedView_required="true"
assistance_java="${package}.dialogs.AvailableAssistanceTypes"
assistance_type="java"
condition_required="true"
condition_required_edit="true"
control="true"
asynchronous="true"
id="assistance_types"
label_en="Supported Assistance types for dropdown list field"/>
Sample Java class
    public class AvailableAssistanceTypes implements IJavaAssistance
{
@Override
public Object getValue(final D2fsContext arg0, final MultiResourceBundle arg1, final Map<String, Object> arg2)
throws DfException, D2fsException {

final XmlNode result = new XmlNodeImpl();

result.appendXmlNode(new XmlOptionEx(1, "DQL", false));
result.appendXmlNode(new XmlOptionEx(2, "Dictonary", false));
result.appendXmlNode(new XmlOptionEx(3, "Java", false));

return result;
}
}

Example for java assistance with dependencies

Below example

      <combo advancedView_required="true" 
assistance_java="com.opentext.d2.smartview.d2svdialogs.assistance.CountryAssistance"
assistance_type="java"
id="country_field"/>

<list advancedView_required="true"
assistance_java="com.opentext.d2.smartview.d2svdialogs.assistance.StateAssistance"
assistance_type="java"
asynchronous="true"
dependencies="country_field"
id="states_field" />

<list advancedView_required="true"
assistance_java="com.opentext.d2.smartview.d2svdialogs.assistance.StateAssistance"
assistance_type="java"
asynchronous="true"
dependencies="country_field"
id="states_field"/>

Sample Java classes

Country class returning few nations data for multi value field using Java Assistance.

    public class CountryAssistance implements IJavaAssistance
{
@Override
public Object getValue(final D2fsContext arg0, final MultiResourceBundle arg1, final Map<String, Object> requestParameters) throws DfException, D2fsException
{
final XmlNode result = new XmlNodeImpl();

result.appendXmlNode(new XmlOptionEx("India", "India", false));
result.appendXmlNode(new XmlOptionEx("USA", "USA", false));
result.appendXmlNode(new XmlOptionEx("Canada", "Canada", false));
return result;
}
}

Fetch states based on the selected country. country_field data is available through requestParameters map in the below class.

public class StateAssistance implements IJavaAssistance
{
@Override
public Object getValue(final D2fsContext arg0, final MultiResourceBundle arg1, final Map<String, Object> requestParameters) throws DfException, D2fsException
{
String country = (String) requestParameters.getOrDefault("country_field", "");
if (!COUNTRY_STATES.containsKey(country.toLowerCase())) {
throw new IllegalArgumentException("Unsupported country: " + country);
}

final XmlNode result = new XmlNodeImpl();
// loop through states and append to XmlNode
for (String state: COUNTRY_STATES.getOrDefault(country.toLowerCase(), Collections.emptyList())) {
result.appendXmlNode(new XmlOptionEx(state, state, false));
}
return result;
}
}

Fetch cities based on the selected states. Multiple states can be passed and based on that cities are returned.

public class CityAssistance implements IJavaAssistance
{
@Override
public Object getValue(final D2fsContext arg0, final MultiResourceBundle arg1, final Map<String, Object> requestParameters) throws DfException, D2fsException
{
String statesField = (String) requestParameters.getOrDefault("states_field", "");
// states_field is a multi value field - use separator to parse values
String[] states = statesField.split(SEPARATOR_VALUE);

final XmlNode result = new XmlNodeImpl();
for(String state: states) {
// loop through states and append to XmlNode
for (String city : STATE_CITIES.getOrDefault(state.toLowerCase(), Collections.emptyList())) {
result.appendXmlNode(new XmlOptionEx(city, city, false));
}
}
return result;
}
}