g_form.clearValue() does not work in the catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 10:07 PM
HI experts,
Using a onchange client script(onchange of variable month_of_overtime) I want to clear the selected value in the selectbox type of a variable in a variable set based on the response received from the Glide Ajax call. Everything works fine as expected but, as soon as I add the statement to clear the selectbox variable it throws an error on the form.
Please look at the screens shot below.
Screenshot of error:
If I remove the clearValue statement the error message does not appear. What could be the reason for this?
Note: the Script include is returning correct value so nothing is wrong there.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 02:27 AM
Hi,
To debug the issue you can use below approach.
If you are using chrome then use ctrl+shift+i to open developer console. check error
please share that screenshot where you found error.
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 10:45 PM
Hi, Can you inspect the browser and share the error details?
Also, make sure to share the complete scripts here.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 12:59 AM
Onchange cs:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var otmonth = g_form.getValue('month_of_overtime');
var ajaxRoles = new GlideAjax('sn_hr_core.XXXXXXXXXXXXXX');
ajaxRoles.addParam('sysparm_name', 'isCorrectOvertimeMonth');
ajaxRoles.addParam('sysparm_app_otmonth', otmonth);
ajaxRoles.getXML(getRolesInfo);
function getRolesInfo(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == '0') {
g_form.clearValue('month_of_overtime');
g_form.showFieldMsg("month_of_overtime", "You are allowed to select only past 2 months.", "error");
}
}
}
Script include function:
isCorrectOvertimeMonth: function() {
var otmonth = this.getParameter('sysparm_app_otmonth');
var currentTime = new GlideDateTime();
var currentMonth = currentTime.getMonthUTC();
if (currentMonth > otmonth) {
var monthDiff = currentMonth - otmonth;
if (monthDiff > 2) {
return false;
} else {
return true;
}
} else {
return true;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 10:40 AM
Use this alternatif
g_form.setValue("variable_name", []);
Please check and let me know if still facing the issue.