- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:37 PM
When you select Planned Start Date on change form, validate if Planned Start Date is after 10 days of current date. If not display an error message below the field and clear the value selected.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:14 AM
Server side aswell you can do that without even script.
Create a Before Insert Business rule on change request table as below
Condition :
And in Actions Tab, you can set as below
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:52 AM
You need to have client script for that to validate instantly.
If you want to go with server script then error message is not shown until you click on save/submit button.
It is easier with UI policy and also better option than server side because it will throw the error message instantly to user when he give the date.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:14 AM
Server side aswell you can do that without even script.
Create a Before Insert Business rule on change request table as below
Condition :
And in Actions Tab, you can set as below
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:50 PM
Hi Nikita,
Here is the script -
Onchange client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('uDateUtils');
ga.addParam('sysparm_name', 'getTenDays');
ga.getXML(alertAnswer);
function alertAnswer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//var end_date=g_form.getValue('start_date');
//var dif=answer-end_date;
var d1=getDateFromFormat( g_form.getValue('start_date'), g_user_date_format);
diff=answer-d1;
if (diff < 1) {
g_form.setValue('start_date', '');
g_form.showErrorBox('start_date', "New start date should be after 10 days from today",'error');
}
}
//Type appropriate comment here, and begin script below
}
Script Include
var uDateUtils = Class.create();
uDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTenDays: function() {
var gdt = new GlideDateTime();
var today = gdt.getLocalDate();
var fdt = new GlideDateTime(today);
fdt.addDays(10);
return fdt.getNumericValue();
},
type: 'uDateUtils'
});
Best Regards,
Prashant
If my answer helped you in any way, please mark this answer as helpful and correct.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:51 PM
Hi there,
Have you considered using a (Catalog) UI Policy to achieve date validations? There's almost no-code needed to achieve date validations this way. Have a look at an article I wrote on this:
No Code date validations thru (Catalog) UI Policies
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:56 PM
Hi,
you can use UI policy for this requirement as below.
create UI policy and when to apply select your date field and use condition as below as before 10 days from now.
On script tab: check select run scripts true and on execute if true use below script.
alert("Enter valid date, You cannot select date before 10 days from now");
g_form.clearValue('yourdatefield');
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar