RE : Multiple Choice Integer - Dynamically create options

Dear All

My apologies for the request which is likely an easy one to resolve.

I want to programmatically add my options to the multiple choice integer.

Please send me the syntax.

I have been looking at the documentation and can’t seem to find it.

Should you have any queries or concerns, please do not hesitate to contact me at your earliest convenience.

Kind regards
Matthew Lucas

Hi Matthew

Unfortunately it is not possible to dynamically/programmatically define the options of a single-choice or multiple-choice data type, as these need to be defined (hardcoded) in either the DataModel or the view itself.

If you want to stick with single-choice or multiple-choice data types then you can dynamically change the displayValue of the pre-defined options in the view in the component itself. Like this.

<single-choice-dropdown bind="ticket.job_type" required="false" >
    <option key="New">{$:getDisplayOption('New')}</option>
    <option key="Workover">{$:getDisplayOption('Workover')}</option>
    <option key="Decomissioning">{$:getDisplayOption('Decomissioning')}</option>
</single-choice-dropdown>

But as you can see, even in this example you cannot change the key options, only the display values. This pattern is typically used to implement translations for single-choice and multiple-choice data types. Please note you can also use this pattern to limit which options are visible to the user in the specific view component, in other words if your data type actually has 10 options but you just want the user to see the first 3, then you can hardcode those three options into the component using this pattern.

That said, the recommended route for creating completely dynamic/programmatic single-choice and multiple-choice options is to use DB objects instead, typically temporary LocalDB objects, but you can also just store it in the normal DB. You basically create all the options you want to present to the user as DB objects and display them using any query bound view component (object-table, object-list, etc.) You then allow the user to select one or more of those objects and store and keep track of the selection in the DB, allowing you to update the UI to give feedback to the user that shows what they have selected. You can accomplish this by changing the color of the objects based on “selection” status or show an icon (like a checkmark) based on the “selection” status.

Dear Tielman

Thank you for your reply.

I will follow the recommended route using LocalDB objects.

1 Like