- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 01:59 AM
i want to validate date is past or not if past want to display error msg using g_form.showfieldmessage
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 02:26 AM
Hi
You can check using Client Script On Change calling a script include where u can check the date with current date
Example Code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('DateandTIme');
ga.addParam('sysparm_name', 'getcurrentdate');
ga.addParam('sysparm_Publised', newValue);
ga.getXML(UpdatePublished);
}
function UpdatePublished(response, newValue){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer){
// g_form_show field msg
g_form.clearValue('published');
return;
}
}
Script include :
var DateandTIme = Class.create();
DateandTIme.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getcurrentdate : function(){
var publisheddate = this.getParameter('sysparm_Publised');
if(publisheddate < gs.nowDateTime()){
return true;
}
else
return false;
},
type: 'DateandTIme'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 02:05 AM
Hi Gomathy,
Have an onChange client script on the date field. Validate if date is past than current date then show the message.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 02:07 AM
Hi Gomathy,
You can achieve this by a Client Script and one Script include called inside the client script. Please find the code for those below:
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('DateValidations ');
ga.addParam('sysparm_name','validateDate');
ga.addParam('sysparm_date',newValue);
ga.getXML(ProcessResult);
function ProcessResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0)
{
g_form.clearValue('extend_trim_access_date');
g_form.showFieldMsg('field_name', 'Please enter a value greater than or equal to Todays date', 'Error');
}
else {
g_form.hideFieldMsg('extend_trim_access_date', true);
}
}
}
Script Include:
var DateValidations = Class.create();
CatalogItemDateValidations.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Creating new Function named 'validateDate'
validateDate: function() {
var ActualStartDate = this.getParameter('sysparm_date');
return gs.dateDiff(gs.now(),ActualStartDate, true)/86400;
},
type: 'CatalogItemDateValidations'
});
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 02:22 AM
Hi Pal,
This is what I have written
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var date_obj = new Date(getDateFromFormat(newValue,user_date_time_format));
var current_date=new Date();
if(date_obj<current_date){
g_form.showFieldMsg('Date','Date should not be past value',error,true);
}
else{
g_form.setValue('Date',current_date);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 02:53 AM
Thank U its working