getDisplayValue returning value from wrong field

___miked___
Mega Contributor

I have multiple fields on a form.   I'm trying to get the value of a choice-list field called 'patient_category'.   But, the following code always returns the value of another field on the form -- the patient_name field.   regardless of what field I specify as the getDisplayValue parameter, the system always returns the value of the patient_name field. I'm totally new to scripting in ServiceNow so am wondering what I am missing.    

function onChange(control, oldValue, newValue, isLoading) {

      if (isLoading || newValue == '') {

          return;

    }  

alert(g_form.getDisplayValue('patient_category'));

    }

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Rahul RJ
Giga Sage
Giga Sage

Hi Mike,



Can you try this code


function onChange(control, oldValue, newValue, isLoading) {


      if (isLoading || newValue == '') {


          return;


    }


        alert(g_form.getDisplayBox('patient_category').value);



    }



P.S: Hit Like or Correct depending on the impact of response


View solution in original post

16 REPLIES 16

Rahul RJ
Giga Sage
Giga Sage

Hi Mike,



Can you try this code


function onChange(control, oldValue, newValue, isLoading) {


      if (isLoading || newValue == '') {


          return;


    }


        alert(g_form.getDisplayBox('patient_category').value);



    }



P.S: Hit Like or Correct depending on the impact of response


This worked.   Thank you for the solution.   I'm now able to return the selection the user makes.   Now that I have that, my next step is to figure out how to filter the items in a related list based on that value.   Thank you again.   And thanks too to everyone who suggested solutions.