"
Allen Andreas, Our ServiceNow Community MVP at Knowledge
2022
Watch Now
! Blog
Auto-populating and validating date Aelds
by Sanjiv Meher Forum Level 4
created 4y ago (edited 4y ago) in Blogs
This post covers few basic use cases related to dates mostly used in Service Catalog
or Change Management
Management.
I have seen a lot of questions in community, where we want to validate a date or we want to
default a date Geld to a future date.
I have gathered few such scenarios and tried to provide solutions with the help of community
answers and my experience.
Most of them are using GlideAjax and onChange Client Script.
If you want to perform validation while record submission as well, you should use them in an
onSubmit Script.
Note
Note: While using them in an onSubmit script, use getXMLWait() instead of a callback
function. Because an onSubmit will not wait for a callback since callbacks are asynchronous.
If you don't want to write another onSubmit script, you can set the Aeld value blank when
validation fails by using g_form.setValue('start_date','')
g_form.setValue('start_date',''), so that user must enter a
another date.
All the client scripts are doing a GlideAjax call to a script include 'DateTimeFunc
DateTimeFunc'. Make
sure you set the UI Type to All in client script to make it work in Service Portal
Portal.
Following are the functions deGned in the script include.
1. addTime
addTime: If you want to add time to your end date based on start date selection
2. addTimeSchedule
addTimeSchedule: If you want to add time to your end date, but the end date shouldn't
fall during weekends or off hours. The schedule must be there is cmn_schedule table.
3. ValidateLeadTime
ValidateLeadTime: If you want to validate a lead time. For example, most of the
organizations wants a lead time of 2 weeks for a comprehensive change. So while submitting
a change, requester should choose a planned start date which is after 2 weeks from today.
4. CompareDates
CompareDates: When you want to compare any two dates and Gnd out which is greater
5. ValidateBlackOuts
ValidateBlackOuts: When you want your request or change implementation date doesn't
fall in a blackout window.
I will keep improving the script based on your feedback and suggestions and add any other
use cases related to dates which are used frequently.
Use Case 1: I want to set a default date
Set default value of the variable (Catalog Item) or Geld (Table) to below.
Add 14 days to current date
javascript:var cdt = new GlideDateTime();cdt.addDays(14);cdt.getDisplayValue();
Set date to current date with time '12:00:00'
javascript:var cdt = new GlideDateTime();cdt.getDisplayValue().split(' ')[0] + ' 12:
Use Case 2: I want to set end date based on start date
Script Type: Client Script
Type: OnChange
Variable/Field Name: start_date
UI Type: All
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
var ga = new GlideAjax('DateTimeFunc');
ga.addParam('sysparm_name', 'addTime');
ga.addParam('start_date', newValue);
ga.addParam('time_to_add', '86400'); // Add 24 hours
ga.getXML(getEndDate);
function getEndDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('end_date',answer);
Use Case 2.1: I want to set end date based on a Schedule
Script Type: Client Script
Type: OnChange
Variable/Field Name: start_date
UI Type: All
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
var ga = new GlideAjax('DateTimeFunc');
ga.addParam('sysparm_name', 'addTimeSchedule');
ga.addParam('start_date', newValue);
ga.addParam('time_to_add', '86400'); // Add 24 hours. If it is a 9*5 schedule (8 hrs
ga.addParam('schedule','8-5 weekdays'); // You must have a record of the schedule in
ga.getXML(getEndDate);
function getEndDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('end_date',answer);
Use Case 3: I want a Lead Time validation for date entered by
requestor
Script Type: Client Script
Type: OnChange
Variable/Field Name: start_date
UI Type: All
:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.hideFieldMsg('start_date');
var start_date = g_form.getValue('start_date');
var ajax = new GlideAjax('DateTimeFunc');
ajax.addParam('sysparm_name', 'ValidateLeadTime');
ajax.addParam('start_date', start_date);
ajax.getXML(validateDate);
function validateDate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer==1)
g_form.showFieldMsg('start_date',"The start date can't be in past",'error');
else if (answer==2)
g_form.showFieldMsg('start_date',"Please consider at least 2 weeks of lead time",'er
Use Case 4: I want to Validate Start Date < End Date
Script Type: Client Script
Type: OnChange
Variable/Field Name: end_date
UI Type: All
:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.hideFieldMsg('end_date');
var ga = new GlideAjax('DateTimeFunc');
ga.addParam('sysparm_name', 'compareDates');
ga.addParam('start_date', g_form.getValue('start_date'));
ga.addParam('end_date', g_form.getValue('end_date'));
ga.getXML(getEndDate);
function getEndDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='true')
g_form.showFieldMsg('end_date','End date should be after start date','error');
Use Case 5: Date requested shouldn't fall in Blackout
Windows
Script Type: Client Script
Type: OnChange
Variable/Field Name: start_date
UI Type: All
:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.hideFieldMsg('start_date');
var ga = new GlideAjax('DateTimeFunc');
ga.addParam('sysparm_name', 'ValidateBlackOuts');
ga.addParam('start_date', newValue); //Pass the date you want to validate
ga.getXML(isBlackout);
function isBlackout(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='true')
g_form.showFieldMsg('start_date','Please select a date outside blackout window','err
Script Include
Name : DateTimeFunc
Client Callable: true
Application: Global
var DateTimeFunc = Class.create();
DateTimeFunc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
addTime: function() {
// Get the Start Date
var start = this.getParameter('start_date');
var timeToAdd = this.getParameter('time_to_add');
var gdt = new GlideDateTime();
gdt.setDisplayValue(start);
//add time to Start Date
gdt.addSeconds(timeToAdd);
//Return the End Date to Client Script
return gdt.getDisplayValue();
:
},
addTimeSchedule: function() {
var start = this.getParameter('start_date');
var timeToAdd = this.getParameter('time_to_add');
var sch = this.getParameter('schedule');
var gdt = new GlideDateTime();
gdt.setDisplayValue(start);
//Get a schedule by name to calculate duration
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', sch);
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);
else
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
//Set the amount of time to add (in seconds)
durToAdd = new GlideDuration(timeToAdd*1000);
var newDateTime = sched.add(gdt, durToAdd, '');
//Return the new date
return newDateTime.getDisplayValue();
},
ValidateLeadTime: function() {
var se_start_date = this.getParameter('start_date');
var opened_date = gs.nowDateTime();
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(opened_date);
var start_date = new GlideDateTime();
start_date.setDisplayValue(se_start_date);
if (se_start_date!='' && start_date<currentDateTime)
return 1; // Start Date Entered is in past
else if (se_start_date!='')
:
{
var dc = new DurationCalculator();
dc.setStartDateTime(currentDateTime);
if (!dc.calcDuration(14*24*3600)) // Add 2 weeks
gs.log("*** Error calculating duration");
var newDateTime = dc.getEndDateTime();
if (start_date < newDateTime)
return 2; // Date entered is within the 2 weeks of lead time
},
compareDates: function() {
var chg_start_date = this.getParameter('start_date');
var chg_end_date = this.getParameter('end_date');
if (chg_start_date > chg_end_date)
return true;
return false;
},
ValidateBlackOuts: function() {
var ch_start_date = this.getParameter('start_date');
var start_date = new GlideDateTime();
start_date.setDisplayValue(ch_start_date);
var g = new GlideRecord('cmn_schedule');
var q = g.addQuery('name', 'Year-End Freeze');
q.addOrCondition('name','IT Infrastructure Blackouts');
g.query();
while (g.next()) {
var sched = new GlideSchedule(g.sys_id);
if (sched.isInSchedule(start_date)){
:
return true;
return false;
},
});
Topics: Technical & Support
# Helpful (22) $ Comment (58) 19366 Views
58 Comments Show All Comments
nandusubbu • 4y ago
N
This is so useful. This blog made my work easy.
Thank you Sanjiv
# Helpful (1) $ Comment
Chaitanya Chowdary • 4y ago
CC
Hi ..
I have used the below script for my start/end date validation in my Helsinki . It is working as
expected but only thing is that it is not accepting today's date. It gives the same error : Start date
cannot be in the past. I assume we need to do some small changes.
Below is my On change Client script for start date:
:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentDateNum;
var startDateNum;
var endDateNum;
g_form.hideFieldMsg('u_security_start_date');
g_form.hideFieldMsg('u_security_end_date');
if (typeof (moment) === "undeGned") {
//Get start date
var startDateStr = g_form.getValue('u_security_start_date');
startDateNum = getDateFromFormat(startDateStr, g_user_date_time_format);
//Get end date
var endDateStr = g_form.getValue('u_security_end_date');
endDateNum = getDateFromFormat(endDateStr, g_user_date_time_format);
//Get current date
:
var currentDateObj = new GlideDate();
var currentDateStr = formatDate(currentDateObj, g_user_date_time_format);
currentDateNum = getDateFromFormat(currentDateStr, g_user_date_time_format);
else
// current date
currentDateNum = moment().valueOf();
//get start date
startDateNum = moment(g_form.getValue('u_security_start_date'));
//get end date
endDateNum = moment(g_form.getValue('u_security_end_date'));
if(newValue == '')
return;
if(endDateNum!='')
{
:
if (endDateNum < startDateNum)
g_form.hideFieldMsg('u_security_start_date');
g_form.showFieldMsg('u_security_start_date', 'Start date must be before the End date','error');
g_form.setValue('u_security_start_date','');
return false;
//if start is past date
if (startDateNum < currentDateNum) {
g_form.hideFieldMsg('u_security_start_date');
g_form.showFieldMsg('u_security_start_date', 'The Start Date cannot be in the past','error');
g_form.setValue('u_security_start_date','');
return false;
It gives the below error for today's date as well.. I want to able to select the current date. Can
you pls help???
:
Thanks
# Helpful (3) $ Comment
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
Can you add an alert before this line to check what values you are getting.
alert('++++++++++++startDateNum ++++++++++++'+startDateNum );
alert('++++++++++currentDateNum+++++++++++'+currentDateNum);
if (startDateNum < currentDateNum) {
g_form.hideFieldMsg('u_security_start_date');
g_form.showFieldMsg('u_security_start_date', 'The Start Date cannot be in the past','error');
g_form.setValue('u_security_start_date','');
return false;
}
:
# Helpful (0) $ Comment
Chaitanya Chowdary % Sanjiv Meher • 4y ago
CC
Hi Sanjiv ,
Thanks for the reply
I have added the comments as given and I see the below. :
from the screen shot its clear that the start date is less than the current date and hence we
are getting the error.
But how can I make sure to select the current date. Is there any time zone issues. is this
expected or any format needs to be done.
Please advise.
Thanks
# Helpful (0) $ Comment
:
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
I don't think, you should compare it based on users date time format. Did you try the use
case 3 and the corresponding script include.
Use Case 3: I want a Lead Time validation for date entered by
requestor
Script Type: Client Script
Type: OnChange
Variable/Field Name: start_date
UI Type: All
1. function onChange(control, oldValue, newValue, isLoading) {
2. if (isLoading || newValue == '') {
3. return;
4. }
5. g_form.hideFieldMsg('start_date');
n. var start_date = g_form.getValue('start_date');
7. var ajax = new GlideAjax('DateTimeFunc');
p. ajax.addParam('sysparm_name', 'ValidateLeadTime');
9. ajax.addParam('start_date', start_date);
10. ajax.getXML(validateDate);
11.
12. }
13.
14.
15. function validateDate(response){
1n. var answer = response.responseXML.documentElement.getAttribute("answer");
17.
1p. if (answer==1)
:
19. g_form.showFieldMsg(
g_form.showFieldMsg('start_date',"The
'start_date',"The start date can't be in
past",'error'
past",'error'); );
20. else if (answer==2)
21. g_form.showFieldMsg('start_date',"Please consider at least 2 weeks of lead
time",'error');
22. }
# Helpful (0) $ Comment
Chaitanya Chowdary % Sanjiv Meher • 4y ago
CC
Hi Sanjiv,
I tried your script and nothing works infact. Any changes I missed .
Here is what i tried:
Client script:
unction onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.hideFieldMsg('u_security_start_date');
var start_date = g_form.getValue('u_security_start_date');
var ajax = new GlideAjax('DateTimeFunc');
ajax.addParam('sysparm_name', 'ValidateLeadTime');
:
ajax.addParam('u_security_start_date', start_date);
ajax.getXML(validateDate);
function validateDate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer==1)
g_form.showFieldMsg('u_security_start_date',"The start date can't be in past",'error');
else if (answer==2)
g_form.showFieldMsg('u_security_start_date',"Please consider at least 2 weeks of lead
time",'error');
**********************************************************************************
Script include:
var DateTimeFunc = Class.create();
DateTimeFunc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ValidateLeadTime: function() {
:
var se_start_date = this.getParameter('u_security_start_date');
var opened_date = gs.nowDateTime();
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(opened_date);
var start_date = new GlideDateTime();
start_date.setDisplayValue(se_start_date);
if (se_start_date!='' && start_date<currentDateTime)
{
return 1; // Start Date Entered is in past
}
else if (se_start_date!='')
{
var dc = new DurationCalculator();
dc.setStartDateTime(currentDateTime);
:
if (!dc.calcDuration(14*24*3600)) // Add 2 weeks
gs.log("*** Error calculating duration");
var newDateTime = dc.getEndDateTime();
if (start_date < newDateTime)
{
return 2; // Date entered is within the 2 weeks of lead time
}
}
},
});
Thanks for your reply
# Helpful (0) $ Comment
Chaitanya Chowdary % Chaitanya Chowdary •
CC
4y ago
I basically want to do the following:
1. start date cannot be in the past
2. end date cannot be in the past
:
3. end date cannot be before start date.
All these are working good, but only thing i am facing is not able to select the current date
in both start date and end date Gelds
# Helpful (0) $ Comment
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
Try this script. Also this is an onchange script. so you need to set the Geld on the client
script to Security Start Date.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.hideFieldMsg('u_security_start_date');
var start_date = g_form.getValue('u_security_start_date');
var ajax = new GlideAjax('DateTimeFunc');
ajax.addParam('sysparm_name', 'ValidateLeadTime');
ajax.addParam('u_security_start_date', start_date);
ajax.getXML(validateDate);
}
:
function validateDate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('+++answer is '+answer);
if (answer==1)
g_form.showFieldMsg('u_security_start_date',"The start date can't be in past",'error');
# Helpful (0) $ Comment
Chaitanya Chowdary % Sanjiv Meher • 4y ago
CC
Hi Sanjiv,
I tried and its not taking the current date, Getting answer=1 for selecting todays date.
See screen shot below.
Any other changes required??
# Helpful (0) $ Comment
:
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
Adding some logs to check whats are the dates. Let me know what you see in the system
log
ValidateLeadTime: function() {
var se_start_date = this.getParameter('u_security_start_date');
var opened_date = gs.nowDateTime();
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(opened_date);
var start_date = new GlideDateTime();
start_date.setDisplayValue(se_start_date);
gs.log('+++++++++++start_date+++++++++'+start_date);
gs.log('+++++++++++currentDateTime+++++++++'+currentDateTime);
if (se_start_date!='' && start_date<currentDateTime)
return 1; // Start Date Entered is in past
}
:
else if (se_start_date!='')
var dc = new DurationCalculator();
dc.setStartDateTime(currentDateTime);
if (!dc.calcDuration(14*24*3600)) // Add 2 weeks
gs.log("*** Error calculating duration");
var newDateTime = dc.getEndDateTime();
if (start_date < newDateTime)
return 2; // Date entered is within the 2 weeks of lead time
},
});
# Helpful (0) $ Comment
Chaitanya Chowdary % Sanjiv Meher • 4y ago
CC
Please see the logs below:
:
# Helpful (0) $ Comment
Chaitanya Chowdary % Chaitanya Chowdary •
CC
4y ago
When I select start date as 10th Feb 2018,
I get the below logs:
So the start date is not getting selected according to what we pick, it is going 1 day less.
what can be the solution for this? pls
Thanks
# Helpful (0) $ Comment
:
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
Can you tell me what is your system time zone and what is the users timezone using
which you are creating the request?
What happens when you try with a user who's timezone is same as system timezone?
# Helpful (0) $ Comment
Sanjiv Meher Forum Level 4 %
Chaitanya Chowdary
• 4y ago Author
Can you tell me what is your system time zone and what is the users timezone using
which you are creating the request?
What happens when you try with a user who's timezone is same as system timezone?
# Helpful (0) $ Comment
Chaitanya Chowdary % Sanjiv Meher • 4y ago
CC
Hi Sajiv,
My system time and instance time is both IST , and still I get the same error. The start date
is less than the current date.
:
# Helpful (0) $ Comment
Chaitanya Chowdary % Chaitanya Chowdary •
CC
4y ago
But from the logs I can see that neither of the start date and end date is showing correctly
to the current date. Start date is having the default time time 18.30 or 6.00 where as the
current time ( i.e 2018-2-12-6.45.36) is not matching the system log timing.i.e 2018 -2 -12 -
12.15.36)
Any idea how to resolve the time zone ? can we have only date function and skip time?
because in my case i do not require time value
Thanks for your reply
# Helpful (0) $ Comment
:
Chaitanya Chowdary % Chaitanya Chowdary •
CC
4y ago
Hi Sajiv,
one more thing I observed, is that i changed the instance time zone to Europe/London and
then I tested. Current date and start date are showing up correctly as below. But only
time varies.
Very much confused with this behavior,. Pls check and let me know what can be done.
# Helpful (0) $ Comment
Chaitanya Chowdary % Chaitanya Chowdary •
CC
4y ago
Hi Sanjiv,
Sorry to have bothered you so much. I tried only date function and modiGed the script
according to my requirement and its WORKING as expected. Thank you so much for your
time and help. Much appreciated.
Thank you:)
# Helpful (0) $ Comment
Siva P % Sanjiv Meher • 2y ago
SP
:
Hi all,
I have a requirement to auto populate on Gelds.
i have a string Geld on my catalog task form which should auto populate with current
week and current month. Can you please suggest me how we can achieve this?
and there is another two text Gelds in my catalog task form. 1.Actual time 2.Total time. i
want add actual time and result to store on total time.
EX: Actual time =10h --> total time = 10h
later i changed actual time = 20h--> total time= 30h should show. How we can do this ?
thanks in advance.
# Helpful (0) $ Comment
rital % Chaitanya Chowdary • 3y ago
In order to resolve this problem, and to not have a message error when you select today's date,
in the script include "DateTimeFunc" add this line
currentDateTime.addDaysLocalTime(-1);
after the declaration of currentDateTime
var currentDateTime = new GlideDateTime();
# Helpful (0) $ Comment
& Show comments ' Hide comments
aansell • 4y ago
This is very helpful Sanjiv. Your work on this is much appreciated both in creating the scripts and
explaining it so clearly. We are working on Gxing some date validation whilst we upgrade to
Kingston and this is a great help.
Best regards,
:
Arthur
# Helpful (0) $ Comment
& Show comments
Brendan Halliday • 4y ago
awesome work Sanjiv!
I used the default date to set it to be 12 months from the current date, ala Use Case 1.
I was wondering what would be the best way to ensure that users were unable to to select a
date past that 12 months? I would assume a client script calling a script include, but just not
sure around the speciGcs. It might be similar to use case 3?
Is this something you have done? it would be a good use case for this blog post in any case :)
# Helpful (0) $ Comment
& Show comments
mayank93 • 4y ago
M
Thank you. That's really useful and saves a lot of time.
I have a query regarding the date time Gelds though. Users are not using the time button within
the calendar and instead entering the time manually. ( eg: 2100, 21:00 ). The system
automatically corrects it to say 21-Jun-2018 21:00:00 on the form, but after submission the time
shows 00:00:00. Is there a way I can Gx that?
Thanks
Mayank.
# Helpful (0) $ Comment
& Show comments
:
mayank93 • 4y ago
M
Doesn't help. The OOB Code is
function validate(value) {
// empty fields are still valid dates
if(!value)
return true;
// We "should" have the global date format defined always defined. but there's al
if(typeof g_user_date_time_format !== 'undefined')
return isDate(value, g_user_date_time_format) ? true : getMessage("Invalid Da
// if we don't have that defined, we can always try guessing
return parseDate(value) !== null ? true : getMessage("Invalid Date");
}
I changed it to the one on docs, didn't help, the time still goes back to 00:00:00. Any idea on how
Service Now automatically changes it to 21:00:00 if the user enters 2100 or 21:00? The time is
changed by the system but it doesn't reyect, instead shows 00:00:00
# Helpful (0) $ Comment
& Show comments
ronnie • 4y ago
R
Hi Sanjiv,
I have a scenario on catalog item where,
when user selects a date for a variable called 'X' and then
there is another variable for example: 'Y' which will be a select box of questions 1,2,3,4.
Based on the selection of this question, the start and end dates will be shown. So if i select '3'
for the variable 'Y' then, three start and end dates will be shown and these end dates should
not be future date of 'X' variable date selected and the start date should be equal or less than
:
the end date. In this case what should be the complete script to achieve this task? I have no idea
as i am very new to such requirement. Could you please help??
# Helpful (0) $ Comment
& Show comments
nani • 4y ago
N
Hi Sanjeev,
I have requirement when HR case selected to particular state ,I need to check any child HR
cases are active(or) inactive related to that hr case.
1) If child cases are active I have to populate conGrmation window with ok/cancel buttons.
a)If they click ok I need to update the parent case to speciGc state.
b) If they click cancel,don't need to update the case
2) If no child cases are active then case need to update
Can you help me with this.I have tried with onchange client script and script includes,but it is not
working.
# Helpful (0) $ Comment
& Show comments
sparhawk • 4y ago
This is excellent! I'm a bit new to coding at all and this is in simple, easy to read and implement
format. Well done! Thanks
# Helpful (0) $ Comment
matt.a • 3y ago
:
Many thanks for this and very helpful.
For the portal, how would I do something similar to this:
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
if(newValue != '') {
//get start date
var startDateStr = g_form.getValue('start_date');
var startDateNum = getDateFromFormat(startDateStr, g_user_date_format);
//get end date
var endDateStr = g_form.getValue('finish_date');
var endDateNum = getDateFromFormat(endDateStr, g_user_date_format);
var diff = endDateNum - startDateNum;
var maxDiff = 84*24*60*60*1000; //30 days * 24 hrs * 60 mins * 60 secs * 1000 ms
if (diff > maxDiff) {
alert('You cannot select a date more than 12 weeks after the start date.');
g_form.setValue('finish_date', '');
}
}
}
}
# Helpful (0) $ Comment
& Show comments
ashthompson • 3y ago
I have tried to leverage use case two for our server decommissioning process. When an SA
selects the Planned Power Off Date, we would like it to auto-populate the Planned Retire Date
for 7 days after (it can remain editable). The JS error I get when I select a Power Off Date is 404
on /xmlhttp.do:1 and unhandled exception in GlideAjax. Is there something else we need to do
to be able to run these types of scripts in our environment? We are on-prem so maybe we need
to upload the includes somewhere?
# Helpful (0) $ Comment
& Show comments
:
Jude Soosairajah • 3y ago
This is a very useful post. Thank you.
# Helpful (0) $ Comment
Aaron M Conroy • 2y ago
AMC
This is very helpful, thank you! Could this apply to the following scenario?
We need a report to cover the current reporting week but the deGnition of a week differs from
the out of the box version in ServiceNow. It's deGned as prior Friday at 3PM to current Friday at
3PM. We are hoping to avoid having to manually update the dates each week but instead have it
done automatically by the system.
Is this possible? Thank you, in advance, for any guidance you can provide here.
# Helpful (0) $ Comment
& Show comments
Youngnam • 2y ago
Y
I tested your code.
but i met error like this.
JavaException: com.glide.script.fencing.MethodNotAllowedException: Function nowDateTime
is not allowed in scope x_00000_needit. Use GlideDateTime instead: new
GlideDateTime().getDisplayValue()
I do a lot of codes to get duration between two dates..
but all things don't work right.
My PDI is on Paris. I am in Korea. is it matters?
# Helpful (0) $ Comment
:
& Show comments
P • 12mo ago
P
It worked like a charm!
# Helpful (0) $ Comment
:
Contact Us ( ) * +
Help
Terms of Use
Privacy Policy
Cookie Preferences
Trademark and Branding
ServiceNow Support
Knowledge Base
© 2022 ServiceNow. All rights reserved.
: