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.

Autopopulate Contact field when the Account is selected.

Community Alums
Not applicable

My code wont work or i missing something? please need help. 

Contact is reference field

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var selectedAccount = g_form.getValue('account');

if (selectedAccount == 'Microsoft' ){

	g_form.setValue('contact', 'Microsoft Service Desk');

}

   //Type appropriate comment here, and begin script below
   
}

 

11 REPLIES 11

Danish Bhairag2
Tera Sage

Hi @Community Alums ,

 

Your script looks good. Can u try putting an alert before if condition to ceck wht u getting in selected account variable?

 

alert(selectedAccount);

 

I believe u might be getting either empty value or some different value rather then Microsoft.

 

Thanks,

Danish

 

Community Alums
Not applicable

Nothing appeared

 

Hi @Community Alums ,

 

After reading the comments what I can think is that the account field might be available on some other table. Can u right click on the label n check that field (click on show field later n see from which table the field is coming)

 

Thanks,

Danish

 

Harish Bainsla
Kilo Patron
Kilo Patron

Hi

Did you select  right onchange fieldname correct which it will work

HarishBainsla_0-1702536341975.png