Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

List Type Field Choice Adding

Prataps135
Mega Sage

Hi,

I just want to dynamically add and remove the choices of a field who's type us LIST on a incident form, On certain conditions. Also there is no table which is Refered in List field.

Thanks and Regards,
Pratap Singh Sisodia

Prataps135_0-1747395368750.png

 

6 REPLIES 6

SumanthDosapati
Mega Sage
Mega Sage

@Prataps135 

Where are you stuck with?

What is the trigger for adding or removing options in list?

Hi @SumanthDosapati ,

You can see here is a field on Incident form named as test which type is LIST.
In that field dropdown choices I just want to add/remove new choices on some conditions.
Like Priority changes to p1 then I need to show 2 choices:-
1. A
2. B
And if Priority is P2 then I want to show only 1 choice:-
1. C

Notes :- There is no table that Is Referred in the Test field.

Prataps135_0-1747396136398.png

 


 

@Prataps135 

You can create a list type field and add choices as in below screenshot

SumanthDosapati_0-1747577815688.png

And then write an onChange client script on priority field. Sample script below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

	var arr = [];
	if(newValue == 1)
	{
		arr = [];
		arr.push('a', 'b');
	}
	else if(newValue == 2)
	{
		arr = [];
		arr.push('c');
	}
	g_form.setValue('u_test', arr);
   
}

 

SumanthDosapati_1-1747577954796.png

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

 

 

@Prataps135 

Did the above solution work? If yes, Accept the solution and mark as helpful to close the thread and benefit other readers.

Regards,
Sumanth