onChange Client Script - How to get value on multiple variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 01:09 AM
How can I check the value on multiple variables on my catalog client script? My current script is only looking at newValue because on the client script form, there is only one option to choose from for variables. In addition, my second part of the script doesn't look at the right section of my script include. Is it possible to execute different information for a delivery date? Also is it possible to update the dates in real time when the values change?
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == '' && g_form.getValue('u_category') == 'Advertisement') {
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.getXML(calThreeDays);
}
else if (newValue == 'Print & Ship' && g_form.getValue('u_category') == 'Advertisement') {
var ajax2 = new GlideAjax('ClientDateTimeUtils');
ajax2.addParam('sysparm_name', 'addDateAmount2');
ajax2.getXML(calThreeDays);
}
function calThreeDays(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_delivery_date', answer);
}
}
Script Include:
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
addDateAmount: function(){
var date = new GlideDateTime(gs.now());
if(date.getDayOfWeekUTC() == 2){
date.addDays(2); // if MONDAY then add 6 days to get Monday
}
else if(date.getDayOfWeekUTC() == 3){
date.addDays(2); // if TUESDAY then add 7 days to get Monday
}
else if(date.getDayOfWeekUTC() == 4){
date.addDays(4); // if WEDNESDAY then add 8 days to get Monday
}
else if(date.getDayOfWeekUTC() == 5){
date.addDays(3); // if THURSDAY then add 3 days to get Monday
}
else if(date.getDayOfWeekUTC() == 6){
date.addDays(2); // if FRIDAY then add 3 days to get Monday
}
else if(date.getDayOfWeekUTC() == 7){
date.addDays(1); // if SATURDAY then add 6 days to get Monday
}
else if(date.getDayOfWeekUTC() == 1){
date.addDays(0); // if SUNDAY then add 6 days to get Monday
}
return date.getDate();
},
addDateAmount2: function(){
var date2 = new GlideDateTime(gs.now());
if(date2.getDayOfWeekUTC() == 2){
date2.addDays(2); // if MONDAY then add 6 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 3){
date2.addDays(7); // if TUESDAY then add 7 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 4){
date2.addDays(4); // if WEDNESDAY then add 8 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 5){
date2.addDays(3); // if THURSDAY then add 3 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 6){
date2.addDays(2); // if FRIDAY then add 3 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 7){
date2.addDays(1); // if SATURDAY then add 6 days to get Monday
}
else if(date2.getDayOfWeekUTC() == 1){
date2.addDays(0); // if SUNDAY then add 6 days to get Monday
}
return date2.getDate();
},
type : 'ClientDateTimeUtils'
});
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 01:22 AM
Hi,
what's your requirement?
what debugging you performed?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 01:31 AM
When Category is set to Advertisement and Output Media is empty set date to 3 days ahead from today's date.
Else If Category is set to Advertisement and Output Media is Print & Ship set date to 7 days ahead.
The code works if I exclude && g_form.getValue('u_category') == 'Advertisement') { so this line seems to be the problem where it doesn't check on category.
As of now, the script is only looking executing on if (newValue == '' and else if (newValue == 'Print & Ship' , again my script is ignoring && g_form.getValue('u_category') == 'Advertisement')
I believe I may have to set a function somewhere in the code to get the value of u_category but I'm not sure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 02:38 AM
Hi,
are you sure you are comparing the correct value for u_category?
if it's choice type then ensure you are comparing correct choice value from backend
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 11:31 AM
Thanks for your response. See below, please let me know if I'm missing something.
To add clarity, the field Output Media shows on the form when Advertisement is chosen as a category. In addition, Output Media is a drop-down that a user has to choose from.