- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2024 01:08 PM
Hi, I have an onChange client script that is adjusting some options and it works great. I am trying to now also make it so that the comments field is no longer required. On line 25 I added 'g_form.setMandatory('comments', false);' like I have in other client scripts, however this is not working. Any reasons why this doesn't work?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
// get user title
var ga = new GlideAjax('FormCheckUtils');
ga.addParam('sysparm_name','recordFieldsClientDisplay');
ga.addParam('sysparm_tablename','u_itd_employee_cost_centers');
ga.addParam('sysparm_fields', 'u_employee_cost_center');
ga.addParam('sysparm_query', 'sys_id='+newValue);
// specify callback Function
ga.getXML((process));
function process(response) {
var value = response.responseXML.documentElement.getAttribute("answer");
value = value.split(',');
var cost_center = value[0];
if (cost_center.toUpperCase().indexOf("PTOT") != -1) {
g_form.showFieldMsg('u_event_code','This field is not mandatory but can make ESS reporting easier - TEST');
g_form.removeOption('u_event_code', 'HRPAY');
g_form.removeOption('u_event_code', 'HREXP');
g_form.removeOption('u_event_code', 'NTPAY');
g_form.setMandatory('comments', false);
g_form.setValue('comments', 'TEST');
}
else {
g_form.setVisible('u_event_code', false);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2024 03:32 PM
Just figured it out, cleared my browser cache and it started working properly. Thanks for your assistance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2024 03:04 PM
Hi @Jared Wason Try inserting try-catch in the process function to make sure there is no error before the setMandatory. It may be that the Script Include isn't properly returning a csv data list.
function process(response) {
try {
var value = response.responseXML.documentElement.getAttribute("answer");
value = value.split(',');
var cost_center = value[0];
if (cost_center.toUpperCase().indexOf("PTOT") != -1) {
g_form.showFieldMsg('u_event_code', 'This field is not mandatory but can make ESS reporting easier - TEST');
g_form.removeOption('u_event_code', 'HRPAY');
g_form.removeOption('u_event_code', 'HREXP');
g_form.removeOption('u_event_code', 'NTPAY');
g_form.setMandatory('comments', false);
g_form.setValue('comments', 'TEST');
} else {
g_form.setVisible('u_event_code', false);
}
} catch (err) {
alert(err.message);
}