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?

Nikita Sangare
Tera Contributor

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.

1 ACCEPTED SOLUTION

@Nikita Sangare 

Server side aswell you can do that without even script.

Create a Before Insert Business rule on change request table as below

Condition :

find_real_file.png

 

And in Actions Tab, you can set as below

find_real_file.png

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

 

View solution in original post

9 REPLIES 9

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

@Nikita Sangare 

Server side aswell you can do that without even script.

Create a Before Insert Business rule on change request table as below

Condition :

find_real_file.png

 

And in Actions Tab, you can set as below

find_real_file.png

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

 

PrashantLearnIT
Giga Sage

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 Roethof
Tera Patron
Tera Patron

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

LinkedIn

Pavankumar_1
Mega Patron

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.

find_real_file.png

 

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

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar