Adding a + button that creates a new choice field

GeraldLorenzett
Tera Contributor

Okay so I need some help with this, ill attach my UI ACTION code and a screen shot.
What I'm trying to do is add a " + " button to one of my choice fields (HAZARD) in my form or right next to it. I have a form that requires many choice fields but INSTEAD of making a gigantic form with an excessive amount of fields id like to add a " + " button next to the first field so that if an end user needs to add another field then they can just click the button and another one will appear if they need. Has anyone ever done this before? I probably need help with the script

GeraldLorenzett_0-1701970182457.png

As you can see all this code does is input a dead " + " button at the bottom.

Here is my code

function addDropdownOption() {
    // Get the dropdown field
    var dropdown = g_form.getControl('u_choice_2');

    // Create a new option
    var option = document.createElement('HAZARD');
    option.text = 'New Option';
    option.value = 'new_option';

    // Add the new option to the dropdown field
    dropdown.add(option);
}

 

1 REPLY 1

SanjivMeher
Kilo Patron
Kilo Patron

I dont know if thats an option with Servicenow forms. 

I would rather create another table linked to this table and provide user to create record in that using embedded list. Below is an example.

 

SanjivMeher_0-1701979629333.png

 

https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/use/using-forms/concept/c_...

 


Please mark this response as correct or helpful if it assisted you with your question.