- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 06:59 AM
Hi All,
Please help me below requirement:
In the catalog item there are two fields for date:
State date and End date
The requirement was user can't choose End date filed more than one year from start date.
Please help me how we will write client script for this requirement.
Thank You.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 02:27 AM
Hi @ashok17 ,
If my response helps you to resolve the issue Accept the solution and close it. So that others can refer and get benefited.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 07:09 AM
Hi Ashok,
You can use glide ajax for the same, in script include add 365 days to start date and define condition as end date should be less than of added date. Hope it helps!.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 07:12 AM
Hi Kiran,
Thanks for response..!
Requesting if possible send me script for above requirement.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 07:22 AM
1) Write an on-change client script pass start date value to script include.
2) Use below code in script include
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 07:57 AM
Hi @ashok17 ,
1. Create onchange client script and script include
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('date_Validation'); //Name of the Script Include
ga.addParam('sysparm_name', 'getDate'); //Name of the function in the script include
ga.addParam('sysparm_start_date', g_form.getValue('start_date')); //Parameter to pass to the script include
ga.addParam('sysparm_end_Date', g_form.getValue('end_date')); //Parameter to pass to the script include
ga.getXMLAnswer(setdetails); //callback funtion
function setdetails(response) {
if(!response){
g_form.clearValue('end_date');
g_form.addInfoMessage('End should not be one year after start Date');
}
}
}
2. Script include: make sure you check the client calable chekc box.
var date_Validation = Class.create();
date_Validation .prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDate: function() {
var start = this.getParameter('sysparm_start_date'); //Passing the start date from the client
var end = this.getParameter('sysparm_end_Date'); //Passing the end date from the client
var dif = gs.dateDiff(start, end, true); //Get the Different between datesin mins
if(dif>0 && dif<=31536000){//365 days mins are equals 31536000
return true;
}
},
type: 'date_Validation '
});
ServiceNow Community MVP 2024.
Thanks,
Pavankumar