Auto populate choice from dropdown

Rutuja K
Giga Guru

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

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello @Rutuja K ,

 

You can easily achieve this by using a client script.

Hint:

    1. Server-Side Choice Count:
      1. Create a Script Include function to count the number of choices available for a specific record.
      2. Use GlideRecord to query the relevant table and field based on the record ID or name.
      3. Return the count of retrieved records.

     

    1. Asynchronous Server-Side Call:
      1. From the client script, use GlideAjax to make an asynchronous call to the Script Include function.
      2. Pass the record ID or name as a parameter to the function.
      3. Handle the response in the onSuccess callback function.

     

    1. Conditional Value Setting:
      1. In the onSuccess callback, check the received choice count.
      2. 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.

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

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.

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

Community Alums
Not applicable

@Rutuja K a quick question here are we storing choices in any table? or you want to directly show it on the form.

 

Community Alums
Not applicable

Hello @Rutuja K ,

 

You can easily achieve this by using a client script.

Hint:

    1. Server-Side Choice Count:
      1. Create a Script Include function to count the number of choices available for a specific record.
      2. Use GlideRecord to query the relevant table and field based on the record ID or name.
      3. Return the count of retrieved records.

     

    1. Asynchronous Server-Side Call:
      1. From the client script, use GlideAjax to make an asynchronous call to the Script Include function.
      2. Pass the record ID or name as a parameter to the function.
      3. Handle the response in the onSuccess callback function.

     

    1. Conditional Value Setting:
      1. In the onSuccess callback, check the received choice count.
      2. 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.