function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tanmay ChoudhariTanmay Choudhari 

How to default dynamic value in radio button depending upon choice available

I have a record choice set and it is used as a choice in radio button in a screen component. The other choice is None.
On the basis of number of records available in record choice set, if only one record is available then I want to default that as a selected choice. If there are more than one records available then I want to default None choice and let user select the required choice.
 
Tried approach - created a formula variable with if logic. In that checked if record choice set contains semi-colon means more than one records are available(CONTAINS({!tField},";")). If true then None choice, if false record choice set as a choice.
 
This formula is not working any other approaches is appreciated. Thanks
Toby GoughToby Gough
I have share some information which i shared so mybe its halpful to you, In order to create a radio button, we need to define the input element and assign it to a variable called input. Then, change its input type to radio. Finally, append the input element to the label element.
SubratSubrat (Salesforce Developers) 
Helo Tanmay ,

To achieve your desired functionality, you can use a formula expression in the "Default Value" property of the radio button in your screen component. The formula should check the number of records in the record choice set and set the default value accordingly. 
{!IF(LEN({!tField}) = 1, {!tField[0].value}, "None")}

Please try with the above formula .

By using this formula expression, the radio button will be pre-selected with the appropriate default value based on the number of records in the choice set. If there's only one record, it will be selected. If there are multiple records, the "None" choice will be selected, allowing the user to make a selection manually.

If this helps , please mark this as Best Answer.
Thank you.
Tanmay ChoudhariTanmay Choudhari
Hi Subrat, Thank you for your suggestion I have done exactly same and updated the name of variable in your formula and put it in the default value of radio button in this way - 

{!IF(LEN({!OrderableProductChoiceSet1}) = 1, {!OrderableProductChoiceSet1[0].value}, {!None})}

But sadly it is not working as expected. I tried with different formula also but didn't worked.

IF( CONTAINS({!OrderableProductChoiceSet1}, ";") , {!None}, {!OrderableProductChoiceSet1})
SubratSubrat (Salesforce Developers) 
Hello ,

Can you try with this one :
{!IF(LEN(OrderableProductChoiceSet1) = 1, OrderableProductChoiceSet1[0].value, None)}

Hope this helps !
Thank you.​​​​​​​