adding multiple question choices for select box

Ujjwal1
Tera Contributor

hi,

I need to add multiple choices (more than 100 items) for select box(variable).

Please suggest, if there is any fast track method to add multiple choices  in select box( other than "insert and stay").

 

Thanks

Ujjwal

11 REPLIES 11

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can write a simple script and just copy the data form excel(as Array) to insert them all.

For Manual entry Insert & Stay would be most optimum. 

 

-Anurag

Thanks @Anurag Tripathi  for response.

 

Can you please give more details on #1 You can write a simple script and just copy the data form excel(as Array) to insert them all.

 

Ujjwal

Something like this, You can run this in a background script. 

I haven't tested it so may need some tweak.

 

   var choice_List= ['one', 'two', 'three'];
   var field = '<sys_id of variable>';
    for (var i = 0; i < choice_List.length; i++) {
        insertRecord(choice_List[i], 'en', choice_List[i], i)
    }

    function insertRecord(name,field, lang, value, order) {
                 var grChoice2 = new GlideRecord("sys_choice");
            grChoice2.initialize();
            grChoice2.setValue('name', name);
            grChoice2.setValue('element', field);
            grChoice2.setValue('language', lang);
            grChoice2.setValue('value', value);
            grChoice2.setValue('order', i*100);

            grChoice2.insert();
        }
    }

 

-Anurag

Ankur Bawiskar
Tera Patron
Tera Patron

@Ujjwal1 

not a good practice to have 100 drop down. not a good user experience.

Why not create a custom table with name field and load data into that.

Then have a reference variable pointing to that table

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader