Question

I am adding "Country of Origin" to InventTable. I created a new field that extends LogisticsAddressCountryRegionId. I added the field to InventTable, then added the field to a Field Group. Everything works as expected. There is a drop down on the form that displays the code (like "USA") and the Description (like "United States") when the drop down is open. When the drop down is closed, it shows "USA". We would like it to show the description instead. Is this possible? Any recommendations how to do it?

Thanks! Tony

Was it helpful?

Solution

A) If the description (in your scenario "United States") was a field and not a display field in the LogisticsAddressCountryRegion then the correct way of doing it would be as follows:

  1. create a new Relation in InventTable, set its Table property to LogisticsAddressCountryRegion
  2. right-click the new Relation, select New > ForeignKey > Single field AlternateKey based
  3. it will automatically create new field LogisticsAddressCountryRegion of type RefRecId (not LogisticsAddressCountryRegionId as in your example!). You can then manually change its ExtendedDataType property from RefRecId to LogisticsAddressCountryRegionRecId
  4. now if you manually drag and drop this field from your form's datasource to a grid or a group in your form, a ReferenceGroup control will be created
  5. by default this control will display CountryRegionId ("US") from LogisticsAddressCountryRegion (same way it works for you now). You don't need it - you want Description to be displayed. In this case the ReferenceGroup's ReplacementFieldGroup property value needs to be changed from AutoIdentification to Description (presumably it's the name of the group in the LogisticsAddressCountryRegion table that contains the Description field).
  6. Voilà - the Description ("United States") is displayed in this form, and the lookup still can be used as before

B) However in your particular scenario this approach cannot be used because there's no Description field in table LogisticsAddressCountryRegion - there's display method displayName, which pulls description from another table (LogisticsAddressCountryRegionTranslation).

In this case somewhat clumsier approach could be used: create an edit method in InventTable, it should use extended data type LogisticsAddressCountryRegionShortName. Code it so that it a) updates your "Country of Origin" field in InventTable based on the entered value and b) displays LogisticsAddressCountryRegion.displayName() based on the "Country of Origin" field value. If you need help coding this method I can advise. Then drag and drop that edit method to create a StringEdit control in your form. That's it. Note that you won't be able to use the value in this control for sorting and filtering in your form.

C) Don't bother with the above. Use 2 controls: one to select the Country of Origin (it will display "USA"), and the other to display the description ("United States"). All you need to change in your current solution is add a new control based on a display method - as soon as you have selected the Country of Origin, the display method will show its description. I recommend you to use this approach.

Nota bene: "Actually - I figured out a way to do this. I created the field to be the same length as "ShortName" which is 255. Then, I just overrode the lookup method on the field." - no no no, this is a very bad idea, don't do it. There must be a ForeignKey relation between InventTable and LogisticsAddressCountryRegion (a link either to CountryRegionId or to RecId).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top