JavaScript error in onLoad client script when hiding fields and using g_form.onChange()

GhitaB
Tera Contributor

Hi everyone,

I’m getting the message “There is a JavaScript error in your browser console” when my onLoad() client script runs on an HR Task form.
After testing, I found that the issue comes from the part of my script where I hide some fields and use g_form.onChange()

var hideOtherInfoFields = [
"ethnicity",
"religion_section",
"blood_group",
"hobbies",
"languages",
"driving_licence_vse",
"disability_card_number"
];

hideOtherInfoFields.forEach(function (field) {
if (g_form.getControl(field)) {
g_form.setVisible(field, false);
g_form.setDisplay(field, false);
g_form.setMandatory(field, false);
}
});

if (g_form.getControl('disability_card_number')) {
g_form.setVisible("disability_card_number", false);
g_form.setDisplay("disability_card_number", false);
g_form.setMandatory("disability_card_number", false);
}

g_form.onChange('do_you_have_any_disability', function () {
if (g_form.getControl('disability_card_number')) {
g_form.setVisible("disability_card_number", false);
g_form.setDisplay("disability_card_number", false);
g_form.setMandatory("disability_card_number", false);
}
});

 

When I comment out this section, the error disappears.

Has anyone faced a similar issue?

Any insights would be appreciated!

Thanks in advance 🙏

5 REPLIES 5

@GhitaB 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader