Below client script is not working

Jyothsna5
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

    // set value in property subcategory based propert
    if ( g_form.getValue('property') == 'detached_house') {
        g_form.setValue('property_subcategory', '3_bedroom_detached_house', '3 Bedroom Detached House');
       
    } else if ( g_form.getValue('property') == 'apartment') {
        g_form.setValue('property_subcategory', '3_bedroom_apartment', '3 Bedroom Apartment');
       
    } else if ( g_form.getValue('property') == 'town_house') {
        g_form.setValue('property_subcategory', '3_bedroom_town_house', '3 Bedroom Town House');
       
    }
 
}
1 ACCEPTED SOLUTION

Bhuvan
Tera Sage

@Jyothsna5 

 

You client script is working fine with provided script,

Bhuvan_0-1754395718820.png

Check if you have configured UI Type, Type, Field name for on change condition and field names used for property, property subcategory in the client script and their values are correct.

 

Bhuvan_1-1754395770332.png

Thanks,

Bhuvan

 

View solution in original post

5 REPLIES 5

KrushnakumaT
Tera Guru

Hi @Jyothsna5 ,
The main cause is that in g_form.setValue() you’re passing three parameters.
In ServiceNow’s g_form.setValue() method, only two parameters are supported for a normal variable or field.

If this response helped, please mark it as the correct answer so it can help others as well.
Thank you!!

 



anshul_goyal
Kilo Sage

Hello @Jyothsna5,

Can you please provide more information?
What's not working in your client script?
And, in your g_form.setValue() method use two parameters only.

If my response resolved your query, kindly mark it as Accepted and Helpful for future reference.

Best Regards,
Anshul

Bhuvan
Tera Sage

@Jyothsna5 

 

You client script is working fine with provided script,

Bhuvan_0-1754395718820.png

Check if you have configured UI Type, Type, Field name for on change condition and field names used for property, property subcategory in the client script and their values are correct.

 

Bhuvan_1-1754395770332.png

Thanks,

Bhuvan

 

Thank you Bhuvan