- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 03:38 PM
Hi
I have below requirement
there is the below date field
Applicant service date( the service of the applicant must be more than 2 years , if it is less than 2 years please don’t allow to enter)
there is another field called Date of joining field of date type
how to validate below Applicant service field ?
anyone has any information please share…
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:34 PM
Hi @Are Kaveri
May be below solution work for you...!!
So here I have done it on incident table on "Actual start" & "Actual end" Fields
You can use your field values here.
Step 1 : Create onChange client script on "Actual end" field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('work_start')) {
var ga = new GlideAjax("DateTimeUtil"); //script include name
ga.addParam('sysparm_name', "getDate"); //function name
ga.addParam('sysparm_date', g_form.getValue('work_start'));
ga.getXMLAnswer(callBack);
}
function callBack(answer) {
if (newValue < answer) {
g_form.showFieldMsg("work_end", "Please enter date more than 2 years from start date");
//may be you can clear value of field here
}
}
}
Step 2 : Write Client Callable Script Include
Name : DateTimeUtil
getDate: function() {
var date = this.getParameter('sysparm_date');
var gdt = new GlideDateTime(date);
gdt.addYearsLocalTime(2);
return gdt;
},
Output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 09:09 PM
Hi @Are Kaveri
You can make use of UI policies to validate date fields.
The below article has step by step information on how to use UI policy to validate dates on form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:09 PM
@Manmohan K my requirement is
The Duration between Date of joining and Applicant service date should be more than 2 years.
if it is less than 2 years from Applicant service date to Date of joining. we should not user to enter and throw some alert.
Date of joining must be less than Applicant service date.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:15 PM
Hi @Are Kaveri ,
Can you please let us know , which date (I mean Current date or Joining date) you are referring to validate Application service date.
i.e. you want to Application service date to be more than 2 years from current date or Joining date
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:34 PM
Hi @Are Kaveri
May be below solution work for you...!!
So here I have done it on incident table on "Actual start" & "Actual end" Fields
You can use your field values here.
Step 1 : Create onChange client script on "Actual end" field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('work_start')) {
var ga = new GlideAjax("DateTimeUtil"); //script include name
ga.addParam('sysparm_name', "getDate"); //function name
ga.addParam('sysparm_date', g_form.getValue('work_start'));
ga.getXMLAnswer(callBack);
}
function callBack(answer) {
if (newValue < answer) {
g_form.showFieldMsg("work_end", "Please enter date more than 2 years from start date");
//may be you can clear value of field here
}
}
}
Step 2 : Write Client Callable Script Include
Name : DateTimeUtil
getDate: function() {
var date = this.getParameter('sysparm_date');
var gdt = new GlideDateTime(date);
gdt.addYearsLocalTime(2);
return gdt;
},
Output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates