AutoPopulate Field from drop down selection

riaz_mansuri
Kilo Guru

Hi,

I am trying to Auto Populate a field when a selection is a made from a drop down using client script.

My script which does not work is below. Any help would be appreciated.

So When "Risk Type" Corporate is selected the "Internal ref" should Auto Populate to CO000

Risk Strat.JPG

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

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

          return;    

  }    

 

  var svc = g_form.getReference('Corporate');    

  g_form.setValue('SR000', internal_ref);        

}    

Thanks

1 ACCEPTED SOLUTION

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


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


          return;


    }


var svc= g_form.getValue("u_risk_type");


alert('Outside'+svc);


if (svc == "Corporate") {


alert('Inside');


g_form.setValue("u_internal_ref", "CO000");


}


}


View solution in original post

21 REPLIES 21

JordanLind
Kilo Guru

try:



var svc= g_form.getValue("u_risk_type"); //this should be the Risky Type column name and not the column label


if (svc = "Corporate") { //this should be the Corporate field value and not the label


g_form.setValue("u_internal_ref", "CO000"); //again, verify the field value for Internal Ref and the field value for CO000


}



http://wiki.servicenow.com/index.php?title=Client_Scripts#What_are_some_of_the_available_helper_func...


Hi Jordan,



Thanks for your reply. The Value "CO000" does not exist anywhere it is just what should be placed in that field. (so if it pre-populates CO000 someone can fill out the remaining in the field).



Below is the current script and the error received.



Many thanks for your help (as you can tell I am not really a scripter)



Thanks


Riaz




RiskIssue2.JPG


Hi Riaz,



There are some syntax error in your script.


Use this script :



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


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


          return;


    }


var svc= g_form.getValue("u_risk_type");


if (svc == "Corporate") {


g_form.setValue("u_internal_ref", "CO000");


}


}


Hi Nishi,



Thanks - The Syntax error did go away but when the drop down "Corporate" is selected the "Internal Ref" is not pre-populating to "CO000".  



Please note: CO000 is just some text.



Any ideas?



Thanks


Riaz