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.

Simple Client Script to hide Choice Value based on something another field contains

richelle_pivec
Mega Guru

I need to make a simple client script that will hide "Messaging" as choice from the Category field when the INC Number does not contain VRT. When it does contain VRT, I want the "Messaging" choice to appear.

I have this as a start, but this would only work if the new value equaled "VRT." As these are INC Numbers, they will always be changing... INC0001 - VRT, INC0002, INC0003 - VRT, etc...

function onChange(control, oldValue, newValue) {

      if (newValue == 'VRT') {

              g_form.addOption('category', 'Messaging');

     

      else {

                      g_form.removeOption('category', 'Messaging');

                     

      }

thanks,

Richelle

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Richelle,



    You can write an onLoad client script and add these lines inside the onLoad function



      if (g_form.getValue('number').toString().indexOf('VRT')>-1) {


              g_form.addOption('category', 'Messaging');


 


      else {


                      g_form.removeOption('category', 'Messaging');


                 


      }



Thanks,


Abhinay




PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

2 REPLIES 2

Abhinay Erra
Giga Sage

Richelle,



    You can write an onLoad client script and add these lines inside the onLoad function



      if (g_form.getValue('number').toString().indexOf('VRT')>-1) {


              g_form.addOption('category', 'Messaging');


 


      else {


                      g_form.removeOption('category', 'Messaging');


                 


      }



Thanks,


Abhinay




PS: Hit like, Helpful or Correct depending on the impact of the response


That worked perfectly! Thank you so much. I'll add that to my list of useful scripts.



Richelle