Show a different widget type in a table record depending on value


I'm building a web screen with service configuration settings. These settings I load from a table which has the following attributes: Description, Value and Type.

The attribute Type has two possible value's: 1, for text and 2 for boolean.

What I would like to achieve is to show the description and value in a table. If the value of the attribute Type is 1, I would like to show the value of the attribute Value in a Input widget. If the value of the attribute Type is 2, I would like to show the value of the attribute Value in a checkbox Widget.

I tried a If widget in the Value column to show one of those two widgets depending on the value of Type, but Outsystems gives an error because a variable can only be uses in one widget at the same time.

Any ideas how to solve this problem?

If is just for showing the result you can always use expressions.
But if you want to show the information with input and check boxs, there is no other way, you'll have to have two separate variables for the two inputs and handle the result on load (and save actions if there is one). 

Hello Matthijs,

can you clarify what data type "value" has? Because it sounds like you have both a bloolean and a different value stored in "value".

You could set the source of your List to a variable that includes a record for the value with both a boolean and another field, like so:

That way, you can use your "if" widget and bind "Boolean" to the checkbox and "Input" to your input. You just need to make sure to map the contents properly during the preparation (if-function checking the "type" value in the mapping).

Best regards,

Hello Matthijs,

I'm assuming that your entity's attribute Value is of text type in order to allow different types of configuration.

In the aggregate you use as source for the Table Records, add two calculated attributes: InputValue and CheckBoxValue, providing the following formula for them (replacing "entity" with your entity name).

For text type:

if(entity.Type = 1, entity.Value, "")

For boolean type depends on how you store the status in Value, all assume "True" for true and "False" for false, because this simplify things, but you can adapt.

if(entity.Type = 2, if(entity.Value = "True", True, False), False)

Now you have 2 new columns that you can use to bind to your input and check box with correct data types.

When you wants to update the record, just use an assign before the update, to set the Value attribute value correctly, with an expression like this:

if(TableRecords.Record.Entity.Type = 1, TableRecords.Record.Entity.InputValue, BooleanToText(TableRecords.Record.Entity.CheckBoxValue))

If you use "True"/"False" for the boolean, you can use the function BooleanToText instead of an IF to save the correct value.

Hope this helps.