Unable to set/clear value of a variable with "onChange" client script - "control" object - within a multi row variableset

Community Alums
Not applicable

Hi,

I am unable to set/clear value of a variable with "onChange" client script - "control" object -  within a multi row variableset. Is it a known issue Or anything wrong with my code or PDI?

 

See below code and attached screenshot.

 

 

g_form.setValue('u_age',''); // working

g_form.setValue(control,''); // not working

g_form.clearValue(control); // not working

 

12 REPLIES 12

Hello Faisal,

As hemant mentioned control returns the html widget of the variable. Here is the reference for you.

find_real_file.png

Ref: https://docs.servicenow.com/bundle/orlando-application-development/page/script/client-scripts/concep...

So use the field name which you want to clear inside your client script. 

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

If you do not want to hardcode a variable name, then may be you can try this

g_form.getFieldNames();

Try this out.

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Avoid using control object to set value or clear value.

Use:

g_form.setValue('actual_fieldName','Value');

g_form.clearValue('actual_fieldName');

 

Please mark reply as Helpful/Correct.

Regards,

Hemant