How to assign String values to Choice?

Sid_Takali
Kilo Patron
Kilo Patron

Hi all,

How to get a string value from table and assign it to a Choice field values. How can I achieve this? I have a fields Phone number, Alternative phone 1 and Alternative phone 2 and I want to fetch it from consumer  and assign it to Choice Field values.   

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @Siddharam Takali ,

You can use addOption() function to achieve the same on the choice value:

The syntax will go something like:

You will need to fetch numbers in a onLoad or onChange client script: Here you can use getReference is user field is present on the form

g_form.addOption("choice_field_name", "your_phone_number","your_phone_number");

g_form.addOption("choice_field_name", "your_alt_phone_number_1","your_alt_phone_number_1");

g_form.addOption("choice_field_name", "your_alt_phone_number_2","your_alt_phone_number_2");

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

 

Best Regards
Aman Kumar

View solution in original post

4 REPLIES 4

Yousaf
Giga Sage

Hi Siddharam,

 

How to set choice field based on string value in client scripts

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Sagar Pagar
Tera Patron

Hi,

What do you mean by assign? Do you want to add as an option?

You can use -

g_form.addOption("field_name", "choice_lable", "choice_value" );

 

to set the values for choice field use -

g_form.setValue("field_name" , ""string_value");

 

Take a look at kb -  How to set choice field based on string value in client scripts

 

Feel free to mark helpful and correct!

Thanks,

Sagar Pagar

The world works with ServiceNow

Aman Kumar S
Kilo Patron

Hi @Siddharam Takali ,

You can use addOption() function to achieve the same on the choice value:

The syntax will go something like:

You will need to fetch numbers in a onLoad or onChange client script: Here you can use getReference is user field is present on the form

g_form.addOption("choice_field_name", "your_phone_number","your_phone_number");

g_form.addOption("choice_field_name", "your_alt_phone_number_1","your_alt_phone_number_1");

g_form.addOption("choice_field_name", "your_alt_phone_number_2","your_alt_phone_number_2");

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

 

Best Regards
Aman Kumar

 

Hi @Siddharam Takali


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar