- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 08:09 AM - edited 08-12-2024 08:09 AM
Hello, I want to create an error message for a question. The question (date) variable is: what_is_the_expected_date_that_the_refresh_must_be_completed_by
The error message should say "Load release across partitions can only be completed on weekends." when users select thursday as a date AND say yes to variable load_release_across_partition.
This is a known problem with SN PRB1694977 as for some reason Thursdays don't work in the UI builder. Support told me ill need to script this one out. I am not too familiar with scripting, is someone able to help me with this?
If more background is needed please see my other post: Re: Can someone explain why trend by Thursday does... - Page 2 - ServiceNow Community
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 09:34 AM
Hi @Andrew Meza ,
Sharing the update set xml to you.
Catalog name is Weekday Catalog item.
After importing just hit the url,
/esc?id=sc_cat_item&sys_id=207ba938c3cc521017aeb61ed40131ee
I believe this will help you.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 12:26 PM - edited 08-12-2024 12:49 PM
Hi @Andrew Meza
Here's the script:
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var date = g_form.getValue('selected_date'); //the name of the date field. what_is_the_expected_date...
//g_form.addInfoMessage((g_form.getValue('load_release_across_partition')));
if (g_form.getValue('load_release_across_partition') == 'Yes') {
var ga = new GlideAjax('global.checkWeekDay'); //Scriptinclude name
ga.addParam('sysparm_name', 'weekDay'); //Method of scriptInclude
ga.addParam('dateSelected', date); //Sending date
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'false') { // Weekday
g_form.clearValue('selected_date'); // [the name of the date field]
g_form.addInfoMessage('Load release across partitions can only be completed on weekends');
}
// g_form.addInfoMessage(answer);
}
}
Script include:
var checkWeekDay = Class.create();
checkWeekDay.prototype = Object.extendsObject(AbstractAjaxProcessor, {
weekDay: function() {
var day1 = this.getParameter('dateSelected')
var dayWithTime = day1 + " 12:00:00";
var gcdt = new GlideDateTime(dayWithTime); // fetch date
gs.print(gcdt);
var day = gcdt.getDayOfWeekLocalTime(); // return the local day number
gs.print("Day:" + day);
if (day == 7 || day == 6){
// gs.addInfoMessage("weekend");
return true;
}
else{
//gs.addInfoMessage("weekday");
return false;
}
},
type: 'checkWeekDay'
});
If this information helps you, please mark it as helpful.
If this solves you question, mark it as solution accepted.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:22 AM
Hi @Andrew Meza ,
Did the script work and you got an error message on selecting Thursday.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 07:26 AM
I do not see it working. Is there something I am missing?
No alterations for script include:
var checkWeekDay = Class.create();
checkWeekDay.prototype = Object.extendsObject(AbstractAjaxProcessor, {
weekDay: function() {
var day1 = this.getParameter('dateSelected')
var dayWithTime = day1 + " 12:00:00";
var gcdt = new GlideDateTime(dayWithTime); // fetch date
gs.print(gcdt);
var day = gcdt.getDayOfWeekLocalTime(); // return the local day number
gs.print("Day:" + day);
if (day == 7 || day == 6){
// gs.addInfoMessage("weekend");
return true;
}
else{
//gs.addInfoMessage("weekday");
return false;
}
},
type: 'checkWeekDay'
});
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var date = g_form.getValue('what_is_the_expected_date_that_the_refresh_must_be_completed_by'); //the name of the date field. what_is_the_expected_date...
//g_form.addInfoMessage((g_form.getValue('load_release_across_partition')));
if (g_form.getValue('load_release_across_partition') == 'Yes') {
var ga = new GlideAjax('global.checkWeekDay'); //Scriptinclude name
ga.addParam('sysparm_name', 'weekDay'); //Method of scriptInclude
ga.addParam('dateSelected', date); //Sending date
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'false') { // Weekday
g_form.clearValue('what_is_the_expected_date_that_the_refresh_must_be_completed_by'); // [the name of the date field]
g_form.addInfoMessage('Load release across partitions can only be completed on weekends');
}
// g_form.addInfoMessage(answer);
}
}
catalog client script screenshot:
Script include screenshot:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 07:38 AM - edited 08-13-2024 07:42 AM
Hi @Andrew Meza
Can you change the UI type in the Catalog client script to 'All' instead of 'Mobile/Service Portal.
I am sure it will work. I personally had tried it.
If this helps you, please mark as helpful!
Regards,
Najmuddin.
