- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:38 AM
I have a requirement to set default value for dropdown when there is only one choice available.
For some records there can be multiple choices available, for some there can be only one. If there is 1 choice available for selection then I want it to auto-populate so that user don't need to select it manually.
Is it possible? Can someone help me with how to do it?
Thank You!
Rutuja
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:16 AM
Hello @Rutuja K ,
You can easily achieve this by using a client script.
Hint:
-
- Server-Side Choice Count:
- Create a Script Include function to count the number of choices available for a specific record.
- Use GlideRecord to query the relevant table and field based on the record ID or name.
- Return the count of retrieved records.
- Asynchronous Server-Side Call:
- From the client script, use GlideAjax to make an asynchronous call to the Script Include function.
- Pass the record ID or name as a parameter to the function.
- Handle the response in the onSuccess callback function.
- Conditional Value Setting:
- In the onSuccess callback, check the received choice count.
- If only one choice is available, use g_form.setValue to set the value of the dropdown field to the first choice.
If I misunderstood something, please provide me with more information to help me understand your requirement better.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:00 AM
It depends on how you are populating the choice list. If you are populating the choice list in a client script, you can add the logic there to see if there is only once choice and then set the value in the field.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:05 AM
Hi Sanjiv,
Thank you for the response.
We are populating choices for "Host" based on another field called "Cloud".
Eg: If cloud type is A then we have created P, Q, R as Host nd they are dependent on A.
What logic I should implement in client script?
:- Rutuja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:20 AM
@Rutuja K a quick question here are we storing choices in any table? or you want to directly show it on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:16 AM
Hello @Rutuja K ,
You can easily achieve this by using a client script.
Hint:
-
- Server-Side Choice Count:
- Create a Script Include function to count the number of choices available for a specific record.
- Use GlideRecord to query the relevant table and field based on the record ID or name.
- Return the count of retrieved records.
- Asynchronous Server-Side Call:
- From the client script, use GlideAjax to make an asynchronous call to the Script Include function.
- Pass the record ID or name as a parameter to the function.
- Handle the response in the onSuccess callback function.
- Conditional Value Setting:
- In the onSuccess callback, check the received choice count.
- If only one choice is available, use g_form.setValue to set the value of the dropdown field to the first choice.
If I misunderstood something, please provide me with more information to help me understand your requirement better.