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-21-2022 11:05 PM
Hi Kalyani,
your client script call on variable set not on catalog item correct???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 10:23 PM
Hi,
have you selected the UI type as ALL?
If not please select UI type as All in Onchange client script.
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:32 PM
Hi Pavan,
I have selected it to All.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 10:52 PM
Hi,
please share your script screenshots will not help us.
Try to add below code in your client script and add field message as well in if loop
ajaxRoles.getXMLAnswer(getRolesinfo); //callback function
function getRolesinfo(response) {
if (answer == 'false') {
g_form.clearValue('month_of_overtime');
}
}
if not resolved please share client script and script include or
If you are using chrome then use ctrl+shift+i to open developer console. see error
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 12:58 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;
}
},