how to print filed :state value in client script

venkatrajesh
Tera Expert

State values: open,closed,pending change,known error

i have tried

var val = g_form.getValue('state');

g_form.addInfoMessage("state "+ val);    

--->getting 1/2/3 depending on state value

to get numeric value     var val=g_form.getIntValue('state'); is enough

so how to print state filed value in text ex:pending change

6 REPLIES 6

Midhun1
Giga Guru

HI Venkat,



Please use


1) alert("   "+ val); //It will pop up the message.


2)g_form.addInfoMessage('The top five fields in this form are mandatory');// It will show at the top of the page


3)g_form.showFieldMsg('impact','Low impact response time can be one week','info'); // IT will show under the field.


Check : http://wiki.servicenow.com/index.php?title=Display_Field_Messages#gsc.tab=0


Hi Midun



actually i am trying to print value in state filed,not having issue with above methods,


finally got the solution


var Value = g_form.getValue('state');


var valdata=g_form.getOption('state', Value).label;


g_form.addInfoMessage("valdata"+valdata);


vinothkumar
Tera Guru

Hi Venkat,



Please try the below code, it will work..


  1. function onChange(control, oldValue, newValue, isLoading, isTemplate) {  
  2. if (isLoading || newValue == '') {  
  3. return;  
  4. }  

  5. var typeValue = g_form.getValue('state');  
  6. var typeLabel = g_form.getOption('state', typeValue).label;  
  7.   alert(typeLabel);
  8. }

Thanks vinoth its working


1.can you please explain why it was not working   for below


                                                        var typeLabel = g_form.getOption('state', typeValue);// with out label




2. please let me know in client script what are the all functions available for printing value of fields


i have tried below these are working,



var group = g_form.getReference('assignment_group');


  g_form.addInfoMessage("group "+ group.name);



var sd = g_form.getValue('short_description');


        g_form.addInfoMessage("shortdesc"+ sd);




3. difference between getValue() and getDisplayValue()