filter field choices after saving

ammar_k
Tera Contributor

Hello, 

I have this script which works correctly with just one issue : 
after saving the record, changing the field's value doesn't change the choices anymore !! 

would you have a solution or  an alternative approach ?

 

than you

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === ''){
      return;
   }
   
g_form.clearOptions('u_claim_subtypes'); 
g_form.addOption('u_claim_subtypes', '--None--',"--None--");
   if (newValue == '30')
   
   {
 g_form.clearOptions('u_claim_subtypes'); 
g_form.addOption('u_claim_subtypes', 'Penalties_Admin',"3.1 Penalties - Admin");
g_form.addOption('u_claim_subtypes', 'Penalties_Back_orders',"3.2 Penalties - Back orders");
g_form.addOption('u_claim_subtypes', 'Penalties_Late_delivery','3.3 Penalties - Late delivery');
   }
   else if(newValue == '40') {
	g_form.clearOptions('u_claim_subtypes'); 
	g_form.addOption('u_claim_subtypes', 'IT_Issue',"4.1 IT Issue");

   }
   else if (newValue == '50')
   
   {
 g_form.clearOptions('u_claim_subtypes'); 
g_form.addOption('u_claim_subtypes', 'Quality_product','5.1 Quality - product');
g_form.addOption('u_claim_subtypes', 'Quality_packaging','5.2 Quality - packaging');
		g_form.addOption('u_claim_subtypes', 'Quality_copacking','5.3 Quality - copacking');
   }
}
  

 

 

4 REPLIES 4

Shivalika
Mega Sage

Hello @ammar_k 

 

Please add another line - g_form.save() at the end of each update. 

 

This will make sure that the changes that you have made on the form are saved. And anyways this is a On Change client script so there will be no issue of being in loop. 

 

I am sure this will solve the issue. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Ankur Bawiskar
Tera Patron
Tera Patron

@ammar_k 

your script will only run when the field changes on which onChange runs

After saving your onChange won't run unless the field is changed

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

@ammar_k 

Hope you are doing good.

Did my reply answer your question?

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

After saving, it doesn't run even when the field changes.