Returning Data to a Lookup

How Can We Help?

< Back

This article talks about resolving Lookup control items not mapped to a value returned from a database.

Potential Issues

The Lookup control in XMPro is used to show a list of items for the user to select. Two of the most common problems encountered with using this control are the following:

  • Mapping of the selected value to a value returned from a database or any other field. This is especially true when two or more fields are returned in the query that is used to populate the items in the Lookup.
  • If a lookup is used in an object group and when extra lines are added, the Lookup in the last line added will often not be populated with items.

Resolution

Using XMConnector based integration goes a long way to make integration to data sources quick and easy and should be the first option as far as possible. However, when it comes to solving the two problems mentioned in the section above, the approach illustrated in the example below should be followed. In the example, there is an ObjectGroup on the form.

The values for the controls are populated using a SQLConnector in the OnLoad method. After that, the SetLookupData method is called to populate the selection in the lookup list. The method uses the DatabaseHelper available in XMPro in this instance to retrieve values from a database, but any other method can be used to retrieve data e.g. web service call.

In the ObjectGroup, the values for each row are placed in the RD1070LocationID and RD1010Category controls. These are of type Label and are hidden in the user’s view. In the SetLookupData method, the code loops through the ObjectGroup and achieves two things:

  • Populates the RD10110Location and RD1090Category Lookup fields with the list of items the user can select from.
  • Depending on the Boolean value passed into the method, sets the value of the RD10110Location and RD1090Category fields accordingly. In the RD10110Location lookup, the value is a combination of the ID and Name columns in the format expected by XMPro when two or more fields are returned from a data source.

The SetLookupData method is called again on the OnRefresh method with a false parameter value to populate the Lookup lists when the user click on the ‘Add Row’ button.

Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X